<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 19-3-28
 * Time: 下午5:31
 */

namespace common\components\huaxiayinhang\bak;


use common\components\tools\RSA;
use yii\base\Component;

class Nbrb extends Component
{
    //const BASE_URL = 'http://picc.chedai.com/';//接口请求地址
//    const BASE_URL = 'http://piccimg.chedai0.com';//接口请求地址//--测试系统环境
//    const BASE_URL = 'http://picc.chedai0.com';//接口请求地址//--正式系统环境
    const BASE_URL = 'http://dev.picc2.chedai0.com/api/jobs/channel';//对接宁波人保请求地址--测试系统环境

    const ATTACHMENT_API = 'http://dev.picc2.chedai0.com/v1/file/upload';//附件上传接口

    //对接宁波人保 add by llf 20190115
    /*对接宁波人保 验签-----------begin*/
    private function encryptBody($requestData, $now) {
        $toEncryptData = $requestData;
        $toEncryptData['timestamp'] = $now;
        return $this->encryptRSA(json_encode($toEncryptData));
    }
    private function encryptRSA($sourceData) {
        //Vendor('RSA.RSA','','.php');
        $rsa = new RSA($_SERVER['DOCUMENT_ROOT']  . '/Lib/Rsa/keyt/renbao_public.pem', $_SERVER['DOCUMENT_ROOT']  . '/Lib/Rsa/keyt/private2.pem');
        return $rsa->encrypt($sourceData);
    }

    private function decryptRSA($encryptData) {
//        Vendor('RSA.RSA','','.php');
        $rsa = new RSA($_SERVER['DOCUMENT_ROOT']  . '/Lib/Rsa/keyt/public2.pem', $_SERVER['DOCUMENT_ROOT']  . '/Lib/Rsa/keyt/private2.pem');
        return $rsa->decrypt($encryptData);
    }

    private function sign($requestBody) {
        ksort($requestBody);
        foreach($requestBody as $key => $each) {
            $requestStringArray[] = $key . "=" . $each;
        }
        $requestString = implode('&', $requestStringArray);
        return $this->signRSA($requestString);
    }

    private function signRSA($sourceData) {
        $pubfile = $_SERVER['DOCUMENT_ROOT']  . '/Lib/Rsa/keyt/public2.pem';
        $prifile =  $_SERVER['DOCUMENT_ROOT']  . '/Lib/Rsa/keyt/private2.pem';
        $rsa = new RSA($pubfile, $prifile);
        $sourceData = strtoupper(bin2hex(hash('sha256', $sourceData, true)));
        return $rsa->sign($sourceData);
    }

    private function verify($sourceData, $sign) {
        ksort($sourceData);
        foreach($sourceData as $key => $each) {
            $responseStringArray[] = $key . "=" . $each;
        }
        $responseString = implode('&', $responseStringArray);
        return $this->verifyRSA($responseString, $sign);
    }

    private function verifyRSA($sourceData, $sign) {
        $rsa = new RSA($_SERVER['DOCUMENT_ROOT']  . '/Lib/Rsa/keyt/renbao_public.pem', $_SERVER['DOCUMENT_ROOT']  . '/Lib/Rsa/keyt/private2.pem');
        $sourceData = strtoupper(bin2hex(hash('sha256', $sourceData, true)));
        return $rsa->verify($sourceData, $sign);
    }

    private function parseResponse($response) {
        $infoSign = $response['infoSign'];
        unset($response['infoSign']);
        $verifyResult = $this->verify($response, $infoSign);
        if(false == $verifyResult) {
            return array('status' => false, 'message' => '验签失败');
        }
        $responseData = json_decode($this->decryptRSA($response['infoContent']), true);
        return array('status' => true, 'data' => $responseData);
    }
    /*对接宁波人保 验签-----------end*/

    //获取指定银行的业务类型列表 add by llf 20190301
    function getProductType(){
        //获取银行id
        $ba_id = $_POST['ba_id'];
//        $ba_id = '3646';
        $b = M('Bank');
        $b_w['b_did'] = $ba_id;
        $b_w['b_status'] = 'ok';
        //根据b_did在bank表中得出b_type
        $bankType = $b->where($b_w)->group('b_type')->select();

        $d_text = [];
        foreach($bankType as $value){
            array_push($d_text, $value['b_type']);
        }
        $d = M('Dict');
        $where = array('d_text' => array('in', $d_text),'d_status' => 'ok');
        $dictList = $d->field(array('d_id','d_text'))->where($where)->group('d_text')->select();
//        echo "<pre/>";
//        var_dump($bank_remark);exit;
        $result = array('status'=>'ok','info'=>'获取业务类型列表成功','data'=>$dictList);
        $this->ajaxReturn($result);
    }

    public $maritalStatus = ['已婚有子女' => '02', '已婚无子女' => '03', '离异单身' => '04', '未婚单身' => '01', '丧偶单身' => '05'];
    public $carUsage = ['个人自用' => '01', '单位自有' => '02', '载客营运' => '03', '载货营运' => '04'];
    public $businessType = ['按揭贷款' => 'BUS_001', '存量' => 'BUS_002', '融资租赁直租' => 'BUS_004', '融资租赁回租' => 'BUS_005'];
    public $carStruct = ['新车' => 'CC_001', '二手车' => 'CC_002','存量车' => 'CC_003'];
    public $Yorn = ['是' => 'Y', '否' => 'N'];
    public $relation = ['配偶' => '03', '子女' => '02', '朋友' => '07', '同事' => '06', '兄弟姐妹' => '04','其他' => '99', '亲属' => '05', '父母' => '01'];
    public $diploma = ['硕士及以上' => '01', '本科' => '02', '大专' => '03', '高中及中专' => '04'];
    public $houseNature = ['商品房' => '01', '房改房' => '02', '安居房' => '03', '集资房' => '04', '其他' => '99'];
    public $companyNature = ['个体' => '07', '机关事业' => '01', '外资' => '03', '合资' => '04', '国有股份' => '02', '民营' => '05', '私营' => '06', '社会团体' => '08'];
    public $workNature = ['工薪阶层' => '01', '农民' => '02', '个体工商户' => '03', '私营企业主' => '04', '自由职业' => '05', '退休' => '06'];
    public $workCareer = [
        '农业' => '01', '林业' => '02', '畜牧业' => '03', '渔业' => '04', '农、林、牧、渔服务业' => '05', '电力、蒸汽、热水的生产和供应业' => '06',
        '煤气生产和供应业' => '07', '自来水的生产和供应业' => '08', '土木工程建筑业' => '09', '邮电通信业' => '10', '金融业' => '11', '保险业' => '12',
        '房地产开发与经营业' => '13', '房地产管理业' => '14', '房地产经纪与代理业' => '15', '国家机关' => '16', '政党机关' => '17', '其它行业' => '18',
        '律师' => '19', '注册会计师' => '20', '医生' => '21', '制造业' => '22', '服务业' => '23', '无职业' => '99',
    ];
    public $workDuty = ['副科（含）以下或一般员工' => '01', '科-副处（含）或初级管理者' => '02', '处-副局（含）或中级管理者' => '03', '局以上或高级管理者' => '04', '其他' => '99'];
    public $mainIncome = ['工资' => '02', '经营、租赁所得' => '01', '投资、佣金' => '03', '其他' => '99', '无' => '04'];
    public $carType = ['国产车' => '01', '进口车' => '02'];
    public $carClass = ['客车' => '01', '货车' => '02'];
    public $powerCteType = ['传统动力' => '01', '新能源' => '02'];
    public $mortgageeType = ['保险公司' => '01', '银行' => '02', '金租公司' => '03'];
    public $carColor = ['黑色' => '01', '白色' => '02', '红色' => '03', '黄色' => '04', '银色' => '05', '香槟色' => '06', '蓝色' => '07', '绿色' => '08', '其他' => '99'];
    public $repayType = ['等额本息' => '01', '等额本金' => '02'];
    public $repayRateb = ['月' => '01', '季' => '02', '年' => '03'];
    public $sex = ['男' => 'M', '女' => 'F'];
    public $loanBusinessType = ['经营性' => '01', '非经营性' => '02'];
    public $housePropertyType = [
        '本地完全产权房屋（住房）' => '01',
        '本地完全产权房屋（商业用房）' => '02',
        '非本地完全产权房屋（住房）' => '03',
        '非本地完全产权房屋（商业用房）' => '04',
        '本地期房（住房）' => '05',
        '本地期房（商业用房）' => '06',
        '非本地期房（住房）' => '07',
        '非本地期房（商业用房）' => '08',
        '其他' => '99',
    ];
    // 【李建林】字典文档有误、学士未找到对应的编码值、需确认
    public $degree = ['名誉博士' => '01', '博士' => '02', '硕士' => '03', '学士' => '', '未知' => '09', '其他' => ''];
    // 【李建林】字典文档有误、【职业所属行业】字典未找到、需确认
    public $workClass = [];
    // 【李建林】字典文档有误、【职称】字典未找到、需确认
    public $workTitle = [];

    public $driveLicenseStatus = ['本人或直系亲属有驾照' => '01', '无驾照' => '02', '其他' => '99'];
    public $carUse = ['非营运' => '01', '营运' => '02'];
    public $licenseType = ['自有车牌' => '01', '公司车牌-挂靠车' => '02', '公司车牌-非挂靠车' => '03'];
    public $pledgeRelate = ['本人' => '01', '挂靠' => '02', '法人' => '03', '法人配偶' => '04'];
    //名族
    public $nation = ['汉族' => '01', '蒙族' => '02', '回族' => '03', '藏族' => '04', '维吾尔族' => '05', '苗族' => '06', '彝族' => '07', '壮族' => '08', '布依族' => '09', '朝鲜族' => '10',
        '满族' => '11', '侗族' => '12', '瑶族' => '13', '白族' => '14', '土家族' => '15', '哈尼族' => '16', '哈萨克族' => '17', '傣族' => '18', '黎族' => '19', '僳僳族' => '20',
        '佤族' => '21', '畲族' => '22', '高山族' => '23', '拉祜族' => '24' , '水族' => '25', '东乡族' => '26', '纳西族' => '27', '景颇族' => '28', '柯尔克孜族' => '29', '土族' => '30',
        '达斡尔族' => '31', '仫佬族' => '32', '羌族' => '33', '布朗族' => '34', '撒拉族' => '35', '毛难族' => '36', '仡佬族' => '37', '锡伯族' => '38', '阿昌族' => '39', '普米族' => '40',
        '塔吉克族' => '41', '怒族' => '42', '乌孜别克族' => '43', '俄罗斯族' => '44', '鄂温克族' => '45', '崩龙族' => '46', '保安族' => '47', '裕固族' => '48', '京族' => '49', '塔塔尔族' => '50',
        '独龙族' => '51', '鄂伦春族' => '52', '赫哲族' => '53', '门巴族' => '54', '珞巴族' => '55', '基诺族' => '56', '外国血统' => '98', '其他' => '99', '外籍人员' => '9A', '无国籍人员' => '9B',
        '香港人' => '9C', '澳门人' => '9D', '台湾人' => '9E', '华侨' => '9F'
    ];
    //抵押人与借贷人关系
    public $mortgageeRelate = ['本人' => '01', '挂靠' => '02', '法人' => '03', '法人配偶' => '04'];

    private function jsonReturns($status, $message)
    {
        return ['status' => $status, 'message' => $message];
    }

    /***********************************对接中国银行北仑银行开始**********************************************/
    /**
     * 对接宁波人保---客户准入接口
     * add by llf 20190111
     * @parameters $url $parms
     * @return $data
     * */
    public function picc_customer_allow($request)
    {
        //合作编号
        $partnerCode = C('NINGBO_PICC.PARTNERCODE');
        //项目编号
        $itemCode = C('NINGBO_PICC.ITEMCODE');
        //子公司编号
        $companyCode = C('NINGBO_PICC.COMPANYCODE');
        //请求流水号(Picc+8位合作编号+Unix时间戳+6位序列号)
        $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);

        //接收前台传送的订单号
        $number = $request['number'];
//		$number = 'GH001-190123-002';
        //购车人信息
        $carManData = M('CarMan')->where(['cm_number' => $number,'cm_type' => '购车人'])->find();
        //配偶信息
        $carManMateData = M('CarMan')->where(['cm_number' => $number,'cm_type' => '配偶'])->find();
        //担保人信息
        $carManDBRData = M('CarMan')->where(['cm_number' => $number,'cm_type' => '担保人'])->select();
        //车辆信息
        $carData = M('Car')->where(['cr_number' => $number])->find();
        //主贷人附件列表
        $attachlistMainMan = [];
        $attacheListMM = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '购车人'])->select();
        if (!empty($attacheListMM)) {
            foreach ($attacheListMM as $key) {
                $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);
                $parms['requestSeqNo'] = $requestSeqNo;
                $parms['itemCode'] = $itemCode;
                $parms['companyCode'] = $companyCode;
                $parms['orderNumber'] = '';
                $attachmentType = '';
                switch ($key['at_name']) {
                    case '身份证正面':
                        $attachmentType = 'loanercardfront';
                        $parms['attachmentType'] = $attachmentType;
                        break;
                    case '身份证反面':
                        $attachmentType = 'loanercardback';
                        $parms['attachmentType'] = $attachmentType;
                        break;
                    case '客户正脸照':
                        $attachmentType = 'loanerface';
                        $parms['attachmentType'] = $attachmentType;
                        break;
                    case '举拍照':
                        $attachmentType = 'loaner3rdauth';
                        $parms['attachmentType'] = $attachmentType;
                        break;
                    default:
                        $parms = [];
                        break;
                }

                if (!empty($parms)) {
                    $parms['file'] = '@./'.$key['at_url'];
                    $parms['number'] = 0;
                    $rst = $this->picc_uploadimg_post(self::ATTACHMENT_API,$parms);
                    file_put_contents(LOG_PATH.'picc_uploadimg_send'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($parms).$rst. "\n\n" , FILE_APPEND);
                    $rst=json_decode($rst, true);
                    if($rst['success'] == 'Y') {
                        array_push($attachlistMainMan, $rst['atNumber']);
                    } else {
                        return $this->jsonReturns(false, '主贷人' . $key['at_name'] . '上传失败');
                        //$this->error('消息：主贷人' . $key['at_name'] . '上传失败');
                    }
                }
            }
        }

        $map = [
            'name' => $carManData['cm_vip_name'],
            'certType' => '01',
            'certNo' => $carManData['cm_card'],
            'phone' => $carManData['cm_tel'],
            'maritalStatus' => isset($this->maritalStatus[$carManData['cm_married']]) ? $this->maritalStatus[$carManData['cm_married']] : '99',
            // 待处理
            'attachlist' => $attachlistMainMan,
            'bankCode' => 'ZGBK',
            'carUsage' => isset($this->carUsage[$carData['cr_bl_carpurpose']]) ? $this->carUsage[$carData['cr_bl_carpurpose']] : '99',
            'businessType' => 'BUS_001',//业务类型--固定为 按揭贷款
            'carStruct' => isset($this->carStruct[$carData['cr_constitute']]) ? $this->carStruct[$carData['cr_constitute']] : '',
            'isDualSign' => isset($this->Yorn[$carData['cr_bl_isdualsign']]) ? $this->Yorn[$carData['cr_bl_isdualsign']] : '',
        ];

        // 配偶
        if (!empty($carManMateData)) {
            $map['hasMate'] = 'Y';
            $map['mateInfo'] = [
                'name' => $carManMateData['cm_vip_name'],
                'certType' => '01',
                'certNo' => $carManMateData['cm_card'],
                'phone' => $carManMateData['cm_tel'],
            ];
            // 待处理
            $attachlistMateMan = [];
            $attacheListMT = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '配偶'])->select();
            if (!empty($attacheListMT)) {
                foreach ($attacheListMT as $key) {
                    $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);
                    $parms['requestSeqNo'] = $requestSeqNo;
                    $parms['itemCode'] = $itemCode;
                    $parms['companyCode'] = $companyCode;
                    $parms['orderNumber'] = '';
                    $attachmentType = '';
                    switch ($key['at_name']) {
                        case '身份证正面':
                            $attachmentType = 'matecardfront';
                            $parms['attachmentType'] = $attachmentType;
                            break;
                        case '身份证反面':
                            $attachmentType = 'matecardback';
                            $parms['attachmentType'] = $attachmentType;
                            break;
                        case '举拍照':
                            $attachmentType = 'mateface';
                            $parms['attachmentType'] = $attachmentType;
                            break;
                        default:
                            $parms = [];
                            break;
                    }

                    if (!empty($parms)) {
                        $parms['file'] = '@./'.$key['at_url'];
                        $parms['number'] = 0;

                        $rst = $this->picc_uploadimg_post(self::ATTACHMENT_API, $parms);
                        file_put_contents(LOG_PATH.'picc_uploadimg_send'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($parms).$rst. "\n\n" , FILE_APPEND);
                        $rst=json_decode($rst, true);
                        if($rst['success'] == 'Y') {
                            array_push($attachlistMateMan, $rst['atNumber']);
                        } else {
                            return $this->jsonReturns(false, '消息：配偶' . $key['at_name'] . '上传失败');
                            //$this->error('消息：配偶' . $key['at_name'] . '上传失败');
                        }
                    }
                }
            }
            $map['mateInfo']['attachlist'] = $attachlistMateMan;
        } else {
            $map['hasMate'] = 'N';
            $map['mateInfo'] = ['name' => '','certType' => '','certNo' => '','phone' => '','attachlist' => ''];
        }

        // 担保人
        if (!empty($carManDBRData)) {
            if (count($carManDBRData) == 1) {
                $map['hasGuar1'] = 'Y';
                $map['guar1Info'] = [
                    'name' => $carManDBRData[0]['cm_vip_name'],
                    'certType' => '01',
                    'certNo' => $carManDBRData[0]['cm_card'],
                    'phone' => $carManDBRData[0]['cm_tel'],
                    'relation' => isset($this->relation[$carManDBRData[0]['cm_relation']]) ? $this->relation[$carManDBRData[0]['cm_relation']] : '99',
                    'attachlist' => [],
                ];

                $attachlistDBRMan = [];
                $attacheListMDBR = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '担保人'])->select();
                if (!empty($attacheListMDBR)) {
                    foreach ($attacheListMDBR as $key) {
                        $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);
                        $parms['requestSeqNo'] = $requestSeqNo;
                        $parms['itemCode'] = $itemCode;
                        $parms['companyCode'] = $companyCode;
                        $parms['orderNumber'] = '';
                        $attachmentType = '';
                        switch ($key['at_name']) {
                            case '身份证正面':
                                $attachmentType = 'guar1cardfront';
                                $parms['attachmentType'] = $attachmentType;
                                break;
                            case '身份证反面':
                                $attachmentType = 'guar1cardback';
                                $parms['attachmentType'] = $attachmentType;
                                break;
                            default:
                                $parms = [];
                                break;
                        }

                        if (!empty($parms)) {
                            $parms['file'] = '@./'.$key['at_url'];
                            $parms['number'] = 0;

                            $rst = $this->picc_uploadimg_post(self::ATTACHMENT_API, $parms);
                            file_put_contents(LOG_PATH.'picc_uploadimg_send'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($parms).$rst. "\n\n" , FILE_APPEND);
                            $rst=json_decode($rst, true);
                            if($rst['success'] == 'Y') {
                                array_push($attachlistDBRMan, $rst['atNumber']);
                            }  else {
                                return $this->jsonReturns(false, '担保人' . $key['at_name'] . '上传失败');
                                //$this->error('消息：担保人' . $key['at_name'] . '上传失败');
                            }
                        }
                    }
                }
                $map['guar1Info']['attachlist'] = $attachlistDBRMan;

                $map['hasGuar2'] = 'N';
                $map['guar2Info'] = ['name' => '','certType' => '','certNo' => '','phone' => '','attachlist' => '','relation' => ''];
            } elseif (count($carManDBRData) >= 2) {
                $map['hasGuar1'] = 'Y';
                $map['guar1Info'] = [
                    'name' => $carManDBRData[0]['cm_vip_name'],
                    'certType' => '01',
                    'certNo' => $carManDBRData[0]['cm_card'],
                    'phone' => $carManDBRData[0]['cm_tel'],
                    'relation' => isset($this->relation[$carManDBRData[0]['cm_relation']]) ? $this->relation[$carManDBRData[0]['cm_relation']] : '99',
                    'attachlist' => [],
                ];

                $map['hasGuar2'] = 'Y';
                $map['guar2Info'] = [
                    'name' => $carManDBRData[1]['cm_vip_name'],
                    'certType' => '01',
                    'certNo' => $carManDBRData[1]['cm_card'],
                    'phone' => $carManDBRData[1]['cm_tel'],
                    'relation' => isset($this->relation[$carManDBRData[1]['cm_relation']]) ? $this->relation[$carManDBRData[1]['cm_relation']] : '99',
                    'attachlist' => [],
                ];

                $attacheListMDBR2 = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '担保人', 'at_name' => '身份证正面照'])->select();
                $attacheListMDBR3 = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '担保人', 'at_name' => '身份证反面照'])->select();

                $dbr_f = [
                    [
                        'attachmentType' => 'guar1cardfront',
                        'file' => $attacheListMDBR2[0]['at_url'],
                        'number' => 0,
                    ],
                    [
                        'attachmentType' => 'guar1cardback',
                        'file' => $attacheListMDBR3[0]['at_url'],
                        'number' => 0,
                    ],
                    [
                        'attachmentType' => 'guar2cardfron',
                        'file' => $attacheListMDBR2[1]['at_url'],
                        'number' => 0,
                    ],
                    [
                        'attachmentType' => 'guar2cardback',
                        'file' => $attacheListMDBR3[1]['at_url'],
                        'number' => 0,
                    ],
                ];

                $dbrlistf1 = [];
                $dbrlistf2 = [];
                foreach ($dbr_f as $key => $vv) {
                    $vv['requestSeqNo'] = 'Picc' . $partnerCode . time() . rand(100000,999999);
                    $parms['itemCode'] = $itemCode;
                    $parms['companyCode'] = $companyCode;
                    $vv['orderNumber'] = '';
                    $rst = $this->picc_uploadimg_post(self::ATTACHMENT_API, $vv);
                    file_put_contents(LOG_PATH.'picc_uploadimg_send'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($vv).$rst. "\n\n" , FILE_APPEND);
                    $rst=json_decode($rst, true);
                    $attachmentType = '';
                    if($rst['success'] == 'Y') {
                        if ($vv['attachmentType'] == 'guar1cardfront' || $vv['attachmentType'] == 'guar1cardback') {
                            array_push($dbrlistf1, $rst['atNumber']);
                        } else {
                            array_push($dbrlistf2, $rst['atNumber']);
                        }
                    }  else {
                        return $this->jsonReturns(false, '担保人资料上传失败');
                        //$this->error('消息：担保人资料上传失败');
                    }
                }

                $map['guar1Info']['attachlist'] = $dbrlistf1;
                $map['guar2Info']['attachlist'] = $dbrlistf2;
            }

        } else {
            $map['hasGuar1'] = 'N';
            $map['guar1Info'] = ['name' => '','certType' => '','certNo' => '','phone' => '','attachlist' => '','relation' => ''];
            $map['hasGuar2'] = 'N';
            $map['guar2Info'] = ['name' => '','certType' => '','certNo' => '','phone' => '','attachlist' => '','relation' => ''];
        }

        file_put_contents(LOG_PATH.'ajax_data'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($map,true). "\n\n" , FILE_APPEND);

        //日期
        $now = time();
        //请求报文
//        echo"<pre/>";
//        var_dump($map);exit;
        $mapData['requestSeqNo'] = $requestSeqNo;//请求流水号
        $mapData['itemCode'] = $itemCode;//项目编号
        $mapData['companyCode'] = $companyCode;//子公司编号
        $mapData['interfaceCode']= 'AccessApply';//接口编号
        $mapData['interfaceVersion'] = 'v1';//接口版本号
        $mapData['infoContent'] = $this->encryptBody($map, $now);//加密报文内容
        $mapData['infoSign'] = $this->sign($mapData);//报文签名
        $url = self::BASE_URL;//请求地址
        $rst = $this->picc_http_post($url, urlencode(json_encode($mapData)));
        file_put_contents(LOG_PATH.'picc_customer_allow'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .$mapData.$rst. "\n\n" , FILE_APPEND);
        if($rst){
            $rst = json_decode(urldecode($rst), true);
            //var_dump($rst);
            $parseData = $this->parseResponse($rst);
            if (!$parseData['status']) {
                return $this->jsonReturns(false, $parseData['message']);
            }

            $finalData = $parseData['data'];
            if ($finalData['code'] == '00') {
                //将客户准入接口数据存入数据库中
                $model = M('PiccAllow');
                $answerdata = [
                    'number' => $number,
                    'code' => $finalData['code'],
                    'errorMsg' => $finalData['errorMsg'],
                    'orderNumber' => $finalData['orderNumber'],
                    'accessNumber' => $finalData['accessNumber'],
                ];
                $model->add($answerdata);
                return $this->jsonReturns(true, '接入人保准入接口成功');
            } else {
                //var_dump($finalData);
                //var_dump(str_replace("<br/>", "", $finalData['errorMsg']));
                file_put_contents(LOG_PATH.'ajax_data'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($finalData,true). "\n\n" , FILE_APPEND);
                return $this->jsonReturns(false, str_replace("<br/>", "", $finalData['errorMsg']));
            }
        } else {
            return $this->jsonReturns(false, '请求人保准入接口失败');
        }
    }


    /**
     * 对接宁波人保---查询省区代码
     * add by llf 20190118
     * @parameters $url $parms
     * @return $data
     * */
    public function get_province_code($county){
        $data = M('Code')->where(['code_name' => $county])->find();
        return !empty($data) ? $data['code_val'] : '';
    }

    /**
     * 对接宁波人保---核保申请接口
     * add by llf 20190115
     * @parameters $url $parms
     * @return $data
     * */
    public function picc_customer_apply($request)
    {
        $number = $request['number'];
//		$number = 'GH001-190123-002';
        //合作编号
        $partnerCode = C('NINGBO_PICC.ITEMCODE');
        //请求流水号(Picc+8位合作编号+Unix时间戳+6位序列号)
        $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);
        //项目编号
        $itemCode = C('NINGBO_PICC.ITEMCODE');
        //子公司编号
        $companyCode = C('NINGBO_PICC.COMPANYCODE');
        $mode = M('PiccAllow');
        $where = [
            'number' => $number,
            'code' => '00',
        ];
        //人保订单编号
        $result = $mode->where($where)->field('orderNumber')->find();
        $orderNumber = $result['orderNumber'];

        file_put_contents(LOG_PATH.'picc_customer_apply'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .$orderNumber. "\n\n" , FILE_APPEND);

        $map = [];
        $map['orderNumber'] = $orderNumber;

        // 根据订单号查询出主贷人的详细信息
        $carManData = M('CarMan')->where(['cm_number' => $number,'cm_type' => '购车人'])->find();
        $carManMateData = M('CarMan')->where(['cm_number' => $number,'cm_type' => '配偶'])->find();
        $carManDBRData = M('CarMan')->where(['cm_number' => $number,'cm_type' => '担保人'])->select();
        $carData = M('Car')->where(['cr_number' => $number])->find();

        // 根据订单号查询订单的风控总结
        $verifyData = M('Verify')->field('v_info')->where(['v_number' => $number, 'v_type' => '经理审核', 'v_status' => '通过'])->find();
        // 基本信息
        $map['baseInfo'] = [
            'branchCode' => '00111',//保险支公司代码
            'salerCode' => 'BJ001',//保险业务员代码
            'businessPlaceCode' => '330108',//业务发生地代码
            'remark' => '',//备注
        ];
        // 主贷人详情
        $emgTouchInfo = json_decode($carManData['cm_urgency_touch'], true);
        $map['mortgagorDetail'] = [
            'age' => (int)$carManData['cm_vip_age'],//年龄
            'sex' =>isset($this->sex[$carManData['cm_vip_sex']]) ? $this->sex[$carManData['cm_vip_sex']] : '',//性别
            'diploma' => isset($this->diploma[$carManData['cm_education']]) ? $this->diploma[$carManData['cm_education']] : '99',
            // 待处理
            'kosekiSSQCode' => $this->get_province_code($carManData['cm_koseki_county']),//户籍省市区代码
            'kosekiDetail' => $carManData['cm_kosekiDetail'],//户籍详细地址
            'isLocal' => isset($this->Yorn[$carManData['cm_islocal']]) ? $this->Yorn[$carManData['cm_islocal']] : '',
            'dwellSSQCode' => $this->get_province_code($carManData['cm_home_distinct']),//现住地址省市区代码
            'dwellDetail' => $carManData['cm_dwellDetail'],//现住详细地址
            'houseNature' => isset($this->houseNature[$carManData['cm_house_nature']]) ? $this->houseNature[$carManData['cm_house_nature']] : '',
            'hasHouseLoan' => isset($this->Yorn[$carManData['cm_has_houseloan']]) ? $this->Yorn[$carManData['cm_has_houseloan']] : '',

            'company' => $carManData['cm_company'],//工作单位
            'companyNature' => isset($this->companyNature[$carManData['cm_company_type']]) ? $this->companyNature[$carManData['cm_company_type']] : '',
            'companySSQCode' => $this->get_province_code($carManData['cm_company_country']),//单位地址省市区代码
            'companyDetail' => $carManData['cm_company_site'],//单位详细地址
            'companyTel' => $carManData['cm_company_tel'],//单位电话
            'workNature' => isset($this->workNature[$carManData['cm_work_nature']]) ? $this->workNature[$carManData['cm_work_nature']] : '99',
            'workCareer' => isset($this->workCareer[$carManData['cm_workCareer']]) ? $this->workCareer[$carManData['cm_workCareer']] : '18',
            'workDuty' => isset($this->workDuty[$carManData['cm_duty']]) ? $this->workDuty[$carManData['cm_duty']] : '99',
            'seniority' => (int)$carManData['cm_seniority'],//工龄
            'mainIncome' => isset($this->mainIncome[$carManData['cm_income_from']]) ? $this->mainIncome[$carManData['cm_income_from']] : '99',
            'monthIncome' => $carManData['cm_income'],//月收入
            'hasSocialSecurity' => isset($this->Yorn[$carManData['cm_social_security']]) ? $this->Yorn[$carManData['cm_social_security']] : '',
            'emgTouchName1' => isset($emgTouchInfo[0]['urgency_touch']) ? $emgTouchInfo[0]['urgency_touch'] : '',//紧急联系人一姓名
            'emgTouchPhone1' => isset($emgTouchInfo[0]['tel']) ? $emgTouchInfo[0]['tel'] : '',//紧急联系人一手机号
            'emgTouchRel1' =>  isset($emgTouchInfo[0]['filiation']) ? (isset($this->relation[$emgTouchInfo[0]['filiation']]) ? $this->relation[$emgTouchInfo[0]['filiation']] : '99') : '',
            'emgTouchName2' => isset($emgTouchInfo[1]['urgency_touch']) ? $emgTouchInfo[1]['urgency_touch'] : '',//紧急联系人二姓名
            'emgTouchPhone2' => isset($emgTouchInfo[1]['tel']) ? $emgTouchInfo[1]['tel'] : '',//紧急联系人二手机号
            'emgTouchRel2' => isset($emgTouchInfo[1]['filiation']) ? (isset($this->relation[$emgTouchInfo[1]['filiation']]) ? $this->relation[$emgTouchInfo[1]['filiation']] : '99') : '',
        ];

        // 配偶详情
        if (!empty($carManMateData)) {
            $map['mateDetail'] = [
                'age' => (int)$carManMateData['cm_vip_age'],//年龄
                'company' => $carManMateData['cm_company'],//工作单位
                'workDuty' => isset($this->workDuty[$carManMateData['cm_duty']]) ? $this->workDuty[$carManMateData['cm_duty']] : '99',
                'mainIncome' => isset($this->mainIncome[$carManMateData['cm_income_from']]) ? $this->mainIncome[$carManMateData['cm_income_from']] : '99',
                'monthIncome' => (int)$carManMateData['cm_income'],//月收入
            ];
        } else {
            $map['mateDetail'] = ['age' => '', 'company' => '', 'workDuty' => '', 'mainIncome' => '', 'monthIncome' => ''];
        }

        // 担保人详情
        if (!empty($carManDBRData)) {
            if (count($carManDBRData) == 1) {
                $map['guar1Detail'] = [
                    'age' => (int)$carManDBRData[0]['cm_vip_age'],//年龄
                    'company' => $carManDBRData[0]['cm_company'],//工作单位
                    'workDuty' => isset($this->workDuty[$carManDBRData[0]['cm_duty']]) ? $this->workDuty[$carManDBRData[0]['cm_duty']] : '99',
                    'mainIncome' => isset($this->mainIncome[$carManDBRData[0]['cm_income_from']]) ? $this->mainIncome[$carManDBRData[0]['cm_income_from']] : '99',
                    'monthIncome' => (int)$carManDBRData[0]['cm_income'],//月收入
                ];
                $map['guar2Detail'] = ['age' => '', 'company' => '', 'workDuty' => '', 'mainIncome' => '', 'monthIncome' => ''];
            } elseif (count($carManDBRData) >= 2) {
                $map['guar1Detail'] = [
                    'age' => (int)$carManDBRData[0]['cm_vip_age'],//年龄
                    'company' => $carManDBRData[0]['cm_company'],//工作单位
                    'workDuty' => isset($this->workDuty[$carManDBRData[0]['cm_duty']]) ? $this->workDuty[$carManDBRData[0]['cm_duty']] : '99',
                    'mainIncome' => isset($this->mainIncome[$carManDBRData[0]['cm_income_from']]) ? $this->mainIncome[$carManDBRData[0]['cm_income_from']] : '99',
                    'monthIncome' => (int)$carManDBRData[0]['cm_income'],//月收入
                ];

                $map['guar2Detail'] = [
                    'age' => (int)$carManDBRData[1]['cm_vip_age'],//年龄
                    'company' => $carManDBRData[1]['cm_company'],//工作单位
                    'workDuty' => isset($this->workDuty[$carManDBRData[1]['cm_duty']]) ? $this->workDuty[$carManDBRData[1]['cm_duty']] : '99',
                    'mainIncome' => isset($this->mainIncome[$carManDBRData[1]['cm_income_from']]) ? $this->mainIncome[$carManDBRData[1]['cm_income_from']] : '99',
                    'monthIncome' => (int)$carManDBRData[1]['cm_income'],//月收入
                ];
            }

        } else {
            $map['guar1Detail'] = ['age' => '', 'company' => '', 'workDuty' => '', 'mainIncome' => '', 'monthIncome' => ''];
            $map['guar2Detail'] = ['age' => '', 'company' => '', 'workDuty' => '', 'mainIncome' => '', 'monthIncome' => ''];
        }

        // 车辆详情
        $map['carDetail'] = [
            'carType' => isset($this->carType[$carData['cr_type']]) ? $this->carType[$carData['cr_type']] : '',
            'carClass' => isset($this->carClass[$carData['cr_classs']]) ? $this->carClass[$carData['cr_classs']] : '',
            'carBrand' => $carData['cr_brand'],//车辆品牌
            'carSeries' => $carData['cr_series'],//车辆车系
            'carSculpt' => $carData['cr_model'],//车辆车型
            'powerCteType' => isset($this->powerCteType[$carData['cr_powertype']]) ? $this->powerCteType[$carData['cr_powertype']] : '',
            'isCompanyLic' => isset($this->Yorn[$carData['cr_is_board']]) ? $this->Yorn[$carData['cr_is_board']] : '',
            'mortgageeType' => isset($this->mortgageeType[$carData['cr_mortgagetype']]) ? $this->mortgageeType[$carData['cr_mortgagetype']] : '',
            'carPrice' => $carData['cr_assessment_money'],//车价
            'carSuggestPrice' => ($carData['cr_price'] == '' ? 0 : ((float)($carData['cr_price'])))*10000,//厂商指导价
            'licInstallSSQCode' => $this->get_province_code($carData['cr_board_city']),//上牌地
            'driverLicBelong' => $carData['cr_owner'],//行驶证车主
            'sculptCode' => $carData['cr_sculptcode'],//车型代码
            'carColor' => isset($this->carColor[$carData['cr_carcolor']]) ? $this->carColor[$carData['cr_carcolor']] : '',
            'engineNumber' => $carData['cr_engineno'],//发动机编号
            'recordDate' => $carData['cr_recorddate'],//登记日期
            'displace' => $carData['cr_displace'],//排量
            'vin' => $carData['cr_vin'],//车架号
            'serviceLife' => (int)$carData['cr_servicelife'],//使用年限
            'miles' => $carData['cr_miles'],//里程数
            'valuate' => $carData['cr_valuate'],//评估价
            'licNumber' => $carData['cr_licnumber'],//车牌号
            'licBelongSSQCode' => $this->get_province_code($carData['cr_board_city']),//车牌归属地省市区代码
            'invoiceNumber' => $carData['cr_invoiceno'],//发票号
            'invoiceIssueEnity' => $carData['cr_invoiceissueenity'],//发票开具单位
        ];

        // 融资详情
        $map['advanceDetail'] = [
            'loanAmt' => $carData['cr_bl_loanmoney'],//贷款本金
            'loanMonth' => (int)$carData['cr_age'],//贷款期数
            'repayType' => '01',//还款方式固定为--等额本息
            'repayRate' => '01',//还款频率固定为--月
            'contractPrice' => $carData['cr_principal_money'],//合同价
            'netPrice' => $carData['cr_bl_netprice'],//车辆净价格
            'coverage' => $carData['cr_bl_insurance'],//保额
            'rate' => $carData['cr_bl_rate'],//保费费率
            'serviceFee' => $carData['cr_service_charge'],//服务费
            'downPayment' => $carData['cr_bl_firstmoney'],//首付金额
            'downPayRate' => $carData['cr_bl_firstpercent'] * 100,//首付比例
        ];

        //风控总结
        $map['riskSummarize']  = isset($verifyData['v_info']) ? $verifyData['v_info'] : '通过';
        //附件列表
        $map['attachlist'] = [];

        // 资料信息先行(1必传0非必传)
        $mainATF = [
            '借款人-驾驶证' => ['loanerdrivinglicense', 1, 1],//主贷人驾驶证
            '借款人-结离婚证或单身证明' => ['loanermaritalcert', 1, 0],//主贷人结婚证/离婚证
            '借款人-征信报告(个人、企业)' => ['loanercreditreport', 1, 0],//主贷人征信报告
            '借款人-户口本' => ['loanerkosekidocument', 4, 1],//主贷人户籍资料
            '借款人-房产证、居住证或暂住证' => ['loanerhousedocument', 8, 0],
            '借款人-收入证明' => ['loanerincomecert', 1, 1],//主贷人收入证明
            '借款人-银行流水' => ['loaneraccountstatement', 8, 1],//主贷人银行流水
            '借款人-企业资料' => ['loanercompanydocument', 4, 0],//主贷人企业资料
            '借款人-保险6单' => ['piccdocument', 16, 1],//人保6单

            '配偶-征信报告(个人、企业)' => ['matecreditreport', 1, 0],//配偶征信报告
            '配偶-银行流水' => ['mateaccountstatement', 8, 0],//配偶银行流水

            '房屋小区大门或村镇标记牌' => ['estatedoor', 1, 0],//小区大门或村镇标记牌
            '房屋门牌号或全景' => ['doornumber', 1, 0],//房屋门牌号或全景
            '借款人与家访人员合照' => ['customerandvistor', 1, 0],//客户与家访员合照
            //'房屋客厅、卧室、厨房、卫生间' => ['', 2],//客厅

            '车头照' => ['carexterior', 4, 0],//车辆外观照（前后左右）
            '车架号' => ['carvin', 1, 0],//车架号
            '后备箱' => ['cartrunk', 1, 0],//后备箱
            '仪表盘' => ['cardashboard', 1, 0],//仪表盘
            '出厂铭牌' => ['carnameplate', 1, 0],//出厂铭牌
            '内部前、后座位' => ['carseats', 4, 0],//内部前后座位
            '行驶证' => ['cardrivinglicense', 1, 0],//行驶证
            '登记证' => ['carregistercert', 1, 0],//登记证
            '车辆与借款人及家访人员合照' => ['carandcustomerandvistor', 1, 0],//车辆、主贷人、家访员合照
            '验车人与抵押车合影' => ['carandchecker', 1, 0],//验车人与车辆合照
            '车辆评估报告' => ['carassessreport', 1, 0],//车辆评估报告
            '购车发票' => ['carinvoicepurchase', 1, 0],//购车发票
        ];

        $atf_data = [];
        foreach ($mainATF as $atfk => $atfv) {
            $tempatf = [];
            $num = $atfv[1];
            $n = $atfv[2];//add by llf 20190304
            $attaData = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_classify' => $atfk])->select();
            if (!empty($attaData)) {
                $trueNum = count($attaData) > $num ? $num : count($attaData);
                for ($i = 0; $i < $trueNum; $i++) {
                    $tempatf['itemCode'] = $partnerCode;
                    $tempatf['orderNumber'] = $orderNumber;
                    $tempatf['attachmentType'] = $atfv[0];
                    $tempatf['companyCode'] = $companyCode;
                    $tempatf['file'] = '@./'.$attaData[$i]['at_url'];
                    $tempatf['number'] = $i;
                    $tempatf['name'] = $atfk;
                }
            }

            //判断是否必传 add by llf 20190304
            if($n == 1 && empty($attaData)){
                return $this->jsonReturns(false,  $atfk . '资料必须上传!');
            }

            if (!empty($tempatf)) {
                $atf_data[] = $tempatf;
            }
        }
        // 发送文件信息
        $finalAttList = [];
        if (!empty($atf_data)) {
            foreach ($atf_data as $atf) {
                $name = $atf['name'];
                unset($atf['name']);
                $atf['requestSeqNo'] = 'Picc' . $partnerCode . time() . rand(100000,999999);
                $rst = $this->picc_uploadimg_post(self::ATTACHMENT_API, $atf);
//                file_put_contents(LOG_PATH.'picc_uploadimg_send'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($vv).$rst. "\n\n" , FILE_APPEND);
                $rst=json_decode($rst, true);
                if($rst['success'] == 'Y') {
//                	array_push($finalAttList, $atf['attachmentType']);
                    array_push($finalAttList, $rst['atNumber']);
                }  else {
//                	var_dump($rst);exit;
//                	return $this->jsonReturns(false, str_replace("<br/>", "", $finalData['errorMsg']));
                    return $this->jsonReturns(false, '【'.$name.'】资料上传失败');
                }
            }
        }

        $map['attachlist'] = $finalAttList;

        file_put_contents(LOG_PATH.'picc_customer_apply_map'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($map,true). "\n\n" , FILE_APPEND);

        $mapData['requestSeqNo'] = $requestSeqNo;//请求流水号
        $mapData['itemCode'] = $itemCode;//项目编号
        $mapData['companyCode'] = $companyCode;//子公司编号
        $mapData['interfaceCode']= 'UnderWriteApply';//接口编号
        $mapData['interfaceVersion'] = 'v1';//接口版本号
        $mapData['infoContent'] = $this->encryptBody($map, time());//加密报文内容
        $mapData['infoSign'] = $this->sign($mapData);//报文签名

//		var_dump($mapData);exit;
        $url = self::BASE_URL;//请求地址
        $rst = $this->picc_http_post($url, urlencode(json_encode($mapData)));
        file_put_contents(LOG_PATH.'picc_customer_apply'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .$mapData.$rst. "\n\n" , FILE_APPEND);
        //将核保申请接口返回的数据存入数据表
        if($rst){
            $rst = json_decode(urldecode($rst), true);
//			var_dump($rst);exit;
            $parseData = $this->parseResponse($rst);
            if (!$parseData['status']) {
                return $this->jsonReturns(false, $parseData['message']);
            }
            file_put_contents(LOG_PATH.'ajax_data'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($parseData,256). "\n\n" , FILE_APPEND);

            $finalData = $parseData['data'];
            if ($finalData['code'] == '00' || $finalData['code'] == '03') {
                $pamode = M('PiccApplyAnswer');
                $data = [
                    'number' => $number,
                    'code' => $finalData['code'],
                    'errorMsg' => $finalData['errorMsg'],
                    'underWriteNumber' => $finalData['underWriteNumber'],
                    'checkResult' => json_encode($finalData['checkResult'], 256),
                ];
                $pamode->add($data);
                return $this->jsonReturns(true, '接入人保核保申请接口成功');
            } else {
                /*var_dump($finalData);
                var_dump(str_replace("<br/>", "", $finalData['errorMsg']));*/
                file_put_contents(LOG_PATH.'ajax_data'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($finalData,256). "\n\n" , FILE_APPEND);
                return $this->jsonReturns(false, str_replace("<br/>", "", $finalData['errorMsg']));
            }
        } else {
//        	file_put_contents(LOG_PATH.'ajax_data'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($finalData,256). "\n\n" , FILE_APPEND);
            return $this->jsonReturns(false, '请求人保核保申请接口失败');
        }
    }


    /**
     * 对接宁波人保---核保审核结果通知接口
     * add by llf 20190118
     * @parameters $url $parms
     * @return $data
     * */
    public function picc_apply_answer(){
        $input = file_get_contents('php://input');
//      file_put_contents(LOG_PATH.'piccback'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($input,256). "\n\n" , FILE_APPEND);
        $requestData = json_decode(urldecode($input), true);

//      file_put_contents(LOG_PATH.'piccback'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($requestData,256). "\n\n" , FILE_APPEND);

        $parseData = $this->parseResponse($requestData);
//      file_put_contents(LOG_PATH.'piccback'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($parseData,256). "\n\n" , FILE_APPEND);
        if (!$parseData['status']) {
            unset($requestData['infoContent']);
            unset($requestData['infoSign']);
            $result = $this->jsonReturns(false, '');
            $map['success'] = 'N';

            $requestData['respCode'] = 'E';
            $requestData['respMsg'] = $result['message'];
            $requestData['infoContent'] = $this->encryptBody($map, time());
            $requestData['infoSign'] = $this->sign($requestData);
            file_put_contents(LOG_PATH.'piccback1028'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($requestData,256). "\n\n" , FILE_APPEND);
            exit(urlencode(json_encode($requestData)));
        }

        $finalData = $parseData['data'];

        $uwinfo = M('PiccApplyAnswer')->field('number')->where(['underWriteNumber' => $finalData['underWriteNumber']])->find();
        // 核保申请编号(通过核保申请接口获取)
        $number = $uwinfo['number'];

        $aduitResult = $finalData['aduitResult'];
        $status = '';
        $v_status = '';
        $v_result = '';
        if ($aduitResult == '00') {
            $v_status = '通过';
            $v_result = "审核通过";
            $status = '终审通过';
        } elseif ($aduitResult == '01') {
            $v_status = '退单';
            $v_result = "审核不通过";
            $status = '初审提交';
        } elseif ($aduitResult == '02') {
            $v_status = '退回';
            $v_result = "资料错误";
            $status = '初审提交';
        }

        $saveData = [
            'v_number' => $number,
            'v_type' => '核保审核',
            'v_status' => $v_status,
            'v_result' => $v_result,
            'v_info' => $finalData['aduitOpinion'],
            'v_view' => '',
            'v_uid' => 0,
            'v_user' => '人保审核',
            'v_time' => time(),
            'v_is_quit' => 1,
            'v_duty_rate' => $finalData['riskRate'],
            'v_fee_rate' => $finalData['rate'],
            'v_highest_loan' => $finalData['maxLoanAmt'],
        ];

        $v_where['v_status'] = '正常';
        $v_where['v_number'] = $number;
        $v_where['v_type'] = '核保审核';
        $v_data = M('Verify') -> where($v_where)-> find();
        if($v_data){
            $v_id = M('Verify')->where($v_where)->save($saveData);
        }else{
            $v_id = M('Verify')->add($saveData);
        }

        M('Order')->where(['o_number' => $number])->save(['o_status' => $status]);

        unset($requestData['infoContent']);
        unset($requestData['infoSign']);


        $map['success'] = 'Y';

        $requestData['respCode'] = 'S';
        $requestData['respMsg'] = '成功';
        $requestData['infoContent'] = $this->encryptBody($map, time());
        $requestData['infoSign'] = $this->sign($requestData);

        file_put_contents(LOG_PATH.'piccback1024'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($requestData,256). "\n\n" , FILE_APPEND);
        exit(urlencode(json_encode($requestData)));
    }

    /**
     * 对接宁波人保---车辆信息补录接口
     * add by llf 20190116
     * @parameters $url $parms
     * @return $data
     * */
    public function picc_carinfo_add($request){
        $number = $request['number'];
        $carData = M('Car')->where(['cr_number' => $number])->find();
        //合作编号
        $partnerCode = C('NINGBO_PICC.ITEMCODE');
        //项目编号
        $itemCode = C('NINGBO_PICC.ITEMCODE');
        //子公司编号
        $companyCode = C('NINGBO_PICC.COMPANYCODE');
        //请求流水号(Picc+8位合作编号+Unix时间戳+6位序列号)
        $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);
        $mode = M('PiccAllow');
        $where = [
            'number' => $number,
            'code' => '00',
        ];
        //人保订单编号
        $result = $mode->where($where)->field('orderNumber')->find();
        $orderNumber = $result['orderNumber'];

        //车辆信息补录数据
        $data = [
            //人保订单编号
            'orderNumber' => $orderNumber,
            //补录详情
            'addDetail' => [
                'sculptCode' => $carData['cr_sculptcode'],//车型代码
                'carColor' => isset($this->carColor[$carData['cr_carcolor']]) ? $this->carColor[$carData['cr_carcolor']] : '',
                'engineNumber' => $carData['cr_engineno'],//发动机编号
                'recordDate' => '',//登记日期
                'displace' => $carData['cr_displace'],//排量
                'vin' => $carData['cr_vin'],//车架号
                'serviceLife' => '',//使用年限
                'miles' => '',//里程数
                'valuate' => '',//评估价
                'licNumber' => '',//车牌号
                'licBelongSSQCode' => '',//车牌归属地省市区代码
                'invoiceNumber' => '',//发票号
                'invoiceIssueEnity' => '',//发票开具单位
            ],
        ];

        //请求报文
        $parms['requestSeqNo'] = $requestSeqNo;//请求流水号
        $parms['itemCode'] = $itemCode;//项目编号
        $parms['companyCode'] = $companyCode;//子公司编号
        $parms['interfaceCode']= 'AdditionalRecordApply';//接口编号
        $parms['interfaceVersion'] = 'v1';//接口版本号
        $parms['infoContent'] = $this->encryptBody($data, time());//加密报文内容
        $parms['infoSign'] = $this->sign($parms);//报文签名

        $url = self::BASE_URL;//请求地址
        $rst = $this->picc_http_post($url, urlencode(json_encode($parms)));
        file_put_contents(LOG_PATH.'picc_carinfo_add'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .$parms.$rst. "\n\n" , FILE_APPEND);

        if($rst){
            $rst = json_decode(urldecode($rst), true);
            $parseData = $this->parseResponse($rst);
            if (!$parseData['status']) {
                return $this->jsonReturns(false, $parseData['message']);
            }

            $finalData = $parseData['data'];
            if ($finalData['code'] == '00') {
                return $this->jsonReturns(true, '接入人保车辆信息补录接口成功');
            } else {
                return $this->jsonReturns(false, str_replace("<br/>", "", $finalData['errorMsg']));
            }
        } else {
            return $this->jsonReturns(false, '请求人保车辆信息补录接口失败');
        }
    }


    /**
     * 对接人保--发送post请求
     * add by hwl
     * @parameters $url $parms
     * @return $data
     * */
    function picc_http_post($url,$parms){
        /* $headers = array();  //设置请求头文件
         $headers[]='Content-Type: application/json';
         $curl = curl_init();
         curl_setopt($curl, CURLOPT_URL, $url);
         curl_setopt($curl, CURLOPT_HTTPHEADER,$headers); //请求头信息
         curl_setopt($curl, CURLOPT_HEADER,0);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($curl, CURLOPT_POST, true); //post传输数据
         curl_setopt($curl, CURLOPT_POSTFIELDS,$parms);
         $data = curl_exec($curl);
         curl_close($curl);
         return $data;*/
        $ch = curl_init($url);
        if(stripos($url,"https://")!==FALSE){
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
        }
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS,$parms);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
        curl_setopt($ch, CURLOPT_HTTPHEADER,
            array('Content-Type: application/json')
        );
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
    }
    /**
     * 对接人保--附件上传--post请求
     * add by hwl
     *  @parameters $url $parms
     * @return $data
     * */
    function picc_uploadimg_post($url,$parms){
        //$headers = array();
        //$headers[]='Content-Type: multipart/form-data';
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        //curl_setopt($curl, CURLOPT_HTTPHEADER,$headers);
        //curl_setopt($curl, CURLOPT_HEADER,0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_POST,1);
        curl_setopt($curl, CURLOPT_POSTFIELDS,$parms);
        $data = curl_exec($curl);
        curl_close($curl);
        //print_r($data);
        return $data;
    }

    /**
     * 对接宁波人保---补录关系人接口
     * add by llf 20190326
     * @parameters $url $parms
     * @return $data
     * */
    public function picc_relation_add($request){
        $number = $request['number'];
        //合作编号
        $partnerCode = C('NINGBO_PICC.ITEMCODE');
        //项目编号
        $itemCode = C('NINGBO_PICC.ITEMCODE');
        //子公司编号
        $companyCode = C('NINGBO_PICC.COMPANYCODE');
        //请求流水号(Picc+8位合作编号+Unix时间戳+6位序列号)
        $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);
        $where = [
            'number' => $number,
            'code' => '00',
        ];
        //人保订单编号
        $map = [];
        $result = M('PiccAllow')->where($where)->field('orderNumber')->find();
        $map['orderNumber'] = $result['orderNumber'];
        //配偶信息
        $carManMateData = M('CarMan')->where(['cm_number' => $number,'cm_type' => '配偶'])->find();
        //担保人信息
        $carManDBRData = M('CarMan')->where(['cm_number' => $number,'cm_type' => '担保人'])->select();
        // 配偶
        if (!empty($carManMateData)) {
            $map['hasMate'] = 'Y';
            $map['mateInfo'] = [
                'name' => $carManMateData['cm_vip_name'],
                'certType' => '01',
                'certNo' => $carManMateData['cm_card'],
                'phone' => $carManMateData['cm_tel'],
            ];
            //附件列表
            $attachlistMateMan = [];
            $attacheListMT = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '配偶'])->select();
            if (!empty($attacheListMT)) {
                foreach ($attacheListMT as $key) {
                    $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);
                    $parms['requestSeqNo'] = $requestSeqNo;
                    $parms['itemCode'] = $itemCode;
                    $parms['companyCode'] = $companyCode;
                    $parms['orderNumber'] = '';
                    switch ($key['at_name']) {
                        case '身份证正面':
                            $attachmentType = 'matecardfront';
                            $parms['attachmentType'] = $attachmentType;
                            break;
                        case '身份证反面':
                            $attachmentType = 'matecardback';
                            $parms['attachmentType'] = $attachmentType;
                            break;
                        case '举拍照':
                            $attachmentType = 'mateface';
                            $parms['attachmentType'] = $attachmentType;
                            break;
                        default:
                            $parms = [];
                            break;
                    }

                    if (!empty($parms)) {
                        $parms['file'] = '@./'.$key['at_url'];
                        $parms['number'] = 0;

                        $rst = $this->picc_uploadimg_post(self::ATTACHMENT_API, $parms);
                        file_put_contents(LOG_PATH.'picc_uploadimg_send'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($parms).$rst. "\n\n" , FILE_APPEND);
                        $rst=json_decode($rst, true);
                        if($rst['success'] == 'Y') {
                            array_push($attachlistMateMan, $rst['atNumber']);
                        } else {
                            return $this->jsonReturns(false, '消息：配偶' . $key['at_name'] . '上传失败');
                            //$this->error('消息：配偶' . $key['at_name'] . '上传失败');
                        }
                    }
                }
            }
            $map['mateInfo']['attachlist'] = $attachlistMateMan;
        } else {
            $map['hasMate'] = 'N';
            $map['mateInfo'] = ['name' => '','certType' => '','certNo' => '','phone' => '','attachlist' => ''];
        }
        // 担保人
        if (!empty($carManDBRData)) {
            if (count($carManDBRData) == 1) {
                $map['hasGuar1'] = 'Y';
                $map['guar1Info'] = [
                    'name' => $carManDBRData[0]['cm_vip_name'],
                    'certType' => '01',
                    'certNo' => $carManDBRData[0]['cm_card'],
                    'phone' => $carManDBRData[0]['cm_tel'],
                    'relation' => isset($this->relation[$carManDBRData[0]['cm_relation']]) ? $this->relation[$carManDBRData[0]['cm_relation']] : '99',
                    'attachlist' => [],
                ];

                $attachlistDBRMan = [];
                $attacheListMDBR = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '担保人'])->select();
                if (!empty($attacheListMDBR)) {
                    foreach ($attacheListMDBR as $key) {
                        $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);
                        $parms['requestSeqNo'] = $requestSeqNo;
                        $parms['itemCode'] = $itemCode;
                        $parms['companyCode'] = $companyCode;
                        $parms['orderNumber'] = '';
                        $attachmentType = '';
                        switch ($key['at_name']) {
                            case '身份证正面':
                                $attachmentType = 'guar1cardfront';
                                $parms['attachmentType'] = $attachmentType;
                                break;
                            case '身份证反面':
                                $attachmentType = 'guar1cardback';
                                $parms['attachmentType'] = $attachmentType;
                                break;
                            default:
                                $parms = [];
                                break;
                        }

                        if (!empty($parms)) {
                            $parms['file'] = '@./'.$key['at_url'];
                            $parms['number'] = 0;

                            $rst = $this->picc_uploadimg_post(self::ATTACHMENT_API, $parms);
                            file_put_contents(LOG_PATH.'picc_uploadimg_send'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($parms).$rst. "\n\n" , FILE_APPEND);
                            $rst=json_decode($rst, true);
                            if($rst['success'] == 'Y') {
                                array_push($attachlistDBRMan, $rst['atNumber']);
                            }  else {
                                return $this->jsonReturns(false, '担保人' . $key['at_name'] . '上传失败');
                                //$this->error('消息：担保人' . $key['at_name'] . '上传失败');
                            }
                        }
                    }
                }
                $map['guar1Info']['attachlist'] = $attachlistDBRMan;

                $map['hasGuar2'] = 'N';
                $map['guar2Info'] = ['name' => '','certType' => '','certNo' => '','phone' => '','attachlist' => '','relation' => ''];
            } elseif (count($carManDBRData) >= 2) {
                $map['hasGuar1'] = 'Y';
                $map['guar1Info'] = [
                    'name' => $carManDBRData[0]['cm_vip_name'],
                    'certType' => '01',
                    'certNo' => $carManDBRData[0]['cm_card'],
                    'phone' => $carManDBRData[0]['cm_tel'],
                    'relation' => isset($this->relation[$carManDBRData[0]['cm_relation']]) ? $this->relation[$carManDBRData[0]['cm_relation']] : '99',
                    'attachlist' => [],
                ];

                $map['hasGuar2'] = 'Y';
                $map['guar2Info'] = [
                    'name' => $carManDBRData[1]['cm_vip_name'],
                    'certType' => '01',
                    'certNo' => $carManDBRData[1]['cm_card'],
                    'phone' => $carManDBRData[1]['cm_tel'],
                    'relation' => isset($this->relation[$carManDBRData[1]['cm_relation']]) ? $this->relation[$carManDBRData[1]['cm_relation']] : '99',
                    'attachlist' => [],
                ];

                $attacheListMDBR2 = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '担保人', 'at_name' => '身份证正面照'])->select();
                $attacheListMDBR3 = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '担保人', 'at_name' => '身份证反面照'])->select();

                $dbr_f = [
                    [
                        'attachmentType' => 'guar1cardfront',
                        'file' => $attacheListMDBR2[0]['at_url'],
                        'number' => 0,
                    ],
                    [
                        'attachmentType' => 'guar1cardback',
                        'file' => $attacheListMDBR3[0]['at_url'],
                        'number' => 0,
                    ],
                    [
                        'attachmentType' => 'guar2cardfron',
                        'file' => $attacheListMDBR2[1]['at_url'],
                        'number' => 0,
                    ],
                    [
                        'attachmentType' => 'guar2cardback',
                        'file' => $attacheListMDBR3[1]['at_url'],
                        'number' => 0,
                    ],
                ];

                $dbrlistf1 = [];
                $dbrlistf2 = [];
                foreach ($dbr_f as $key => $vv) {
                    $vv['requestSeqNo'] = 'Picc' . $partnerCode . time() . rand(100000,999999);
                    $parms['itemCode'] = $itemCode;
                    $parms['companyCode'] = $companyCode;
                    $vv['orderNumber'] = '';
                    $rst = $this->picc_uploadimg_post(self::ATTACHMENT_API, $vv);
                    file_put_contents(LOG_PATH.'picc_uploadimg_send'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($vv).$rst. "\n\n" , FILE_APPEND);
                    $rst=json_decode($rst, true);
                    $attachmentType = '';
                    if($rst['success'] == 'Y') {
                        if ($vv['attachmentType'] == 'guar1cardfront' || $vv['attachmentType'] == 'guar1cardback') {
                            array_push($dbrlistf1, $rst['atNumber']);
                        } else {
                            array_push($dbrlistf2, $rst['atNumber']);
                        }
                    }  else {
                        return $this->jsonReturns(false, '担保人资料上传失败');
                        //$this->error('消息：担保人资料上传失败');
                    }
                }

                $map['guar1Info']['attachlist'] = $dbrlistf1;
                $map['guar2Info']['attachlist'] = $dbrlistf2;
            }

        } else {
            $map['hasGuar1'] = 'N';
            $map['guar1Info'] = ['name' => '','certType' => '','certNo' => '','phone' => '','attachlist' => '','relation' => ''];
            $map['hasGuar2'] = 'N';
            $map['guar2Info'] = ['name' => '','certType' => '','certNo' => '','phone' => '','attachlist' => '','relation' => ''];
        }
        //请求报文
        $mapdata['requestSeqNo'] = $requestSeqNo;//请求流水号
        $mapdata['itemCode'] = $itemCode;//项目编号
        $mapdata['companyCode'] = $companyCode;//子公司编号
        $mapdata['interfaceCode']= 'AddRelation';//接口编号
        $mapdata['interfaceVersion'] = 'v1';//接口版本号
        $mapdata['infoContent'] = $this->encryptBody($map, time());//加密报文内容
        $mapdata['infoSign'] = $this->sign($mapdata);//报文签名

        $url = self::BASE_URL;//请求地址
        $rst = $this->picc_http_post($url, urlencode(json_encode($mapdata)));
        file_put_contents(LOG_PATH.'picc_relation_add'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .$mapdata.$rst. "\n\n" , FILE_APPEND);

        if($rst){
            $rst = json_decode(urldecode($rst), true);
            $parseData = $this->parseResponse($rst);
            if (!$parseData['status']) {
                return $this->jsonReturns(false, $parseData['message']);
            }

            $finalData = $parseData['data'];
            if ($finalData['code'] == '00') {
                return $this->jsonReturns(true, '接入人保补录关系人接口成功');
            } else {
                return $this->jsonReturns(false, str_replace("<br/>", "", $finalData['errorMsg']));
            }
        } else {
            return $this->jsonReturns(false, '请求人保补录关系人接口失败');
        }
    }


    /***********************************对接中国银行北仑银行结束**********************************************/




    /***********************************对接东海线上银行开始**********************************************/

    /**
     * 对接宁波人保---客户准入接口---东海线上银行
     * add by llf 20190111
     * @parameters $url $parms
     * @return $data
     * */
    public function picc_customer_allow_dh($request)
    {
        //合作编号
        $partnerCode = C('NINGBO_PICC.PARTNERCODE');
        //项目编号
        $itemCode = C('NINGBO_PICC.ITEMCODE');
        //子公司编号
        $companyCode = C('NINGBO_PICC.COMPANYCODE');
        //请求流水号(Picc+8位合作编号+Unix时间戳+6位序列号)
        $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);

        //接收前台传送的订单号
        $number = $request['number'];
//		$number = 'GH001-190123-002';
        //购车人信息
        $carManData = M('CarMan')->where(['cm_number' => $number,'cm_type' => '购车人'])->find();
        //配偶信息
        $carManMateData = M('CarMan')->where(['cm_number' => $number,'cm_type' => '配偶'])->find();
        //担保人信息
        $carManDBRData = M('CarMan')->where(['cm_number' => $number,'cm_type' => '担保人'])->select();
        //车辆信息
        $carData = M('Car')->where(['cr_number' => $number])->find();
        //主贷人附件列表
        $attachlistMainMan = [];
        $attacheListMM = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '购车人'])->select();
        if (!empty($attacheListMM)) {
            foreach ($attacheListMM as $key) {
                $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);
                $parms['requestSeqNo'] = $requestSeqNo;
                $parms['itemCode'] = $itemCode;
                $parms['companyCode'] = $companyCode;
                $parms['orderNumber'] = '';
                $attachmentType = '';
                switch ($key['at_name']) {
                    case '身份证正面':
                        $attachmentType = 'loanercardfront';
                        $parms['attachmentType'] = $attachmentType;
                        break;
                    case '身份证反面':
                        $attachmentType = 'loanercardback';
                        $parms['attachmentType'] = $attachmentType;
                        break;
                    case '客户正脸照':
                        $attachmentType = 'loanerface';
                        $parms['attachmentType'] = $attachmentType;
                        break;
                    case '举拍照':
                        $attachmentType = 'loaner3rdauth';
                        $parms['attachmentType'] = $attachmentType;
                        break;
                    default:
                        $parms = [];
                        break;
                }

                if (!empty($parms)) {
                    $parms['file'] = '@./'.$key['at_url'];
                    $parms['number'] = 0;
                    $rst = $this->picc_uploadimg_post(self::ATTACHMENT_API,$parms);
                    file_put_contents(LOG_PATH.'picc_uploadimg_send'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($parms).$rst. "\n\n" , FILE_APPEND);
                    $rst=json_decode($rst, true);
                    if($rst['success'] == 'Y') {
                        array_push($attachlistMainMan, $rst['atNumber']);
                    } else {
                        return $this->jsonReturns(false, '主贷人' . $key['at_name'] . '上传失败');
                        //$this->error('消息：主贷人' . $key['at_name'] . '上传失败');
                    }
                }
            }
        }

        $map = [
            'name' => $carManData['cm_vip_name'],
            'certType' => '01',
            'certNo' => $carManData['cm_card'],
            'sex' => $carManData['cm_vip_sex'],
            'maritalStatus' => isset($this->maritalStatus[$carManData['cm_married']]) ? $this->maritalStatus[$carManData['cm_married']] : '99',
            'phone' => $carManData['cm_tel'],
            'nation' => isset($this->nation[$carManData['cm_nation']]) ? $this->nation[$carManData['cm_nation']] : '99',
            'cardNo' => $carManData['cm_card_no'],
            'idvalidStart' => $carManData['cm_cert_start_date'],
            'idvalidEnd' => $carManData['cm_cert_start_end'],
            // 待处理
            'attachlist' => $attachlistMainMan,
            'bankCode' => 'DHBK',
            'carUsage' => isset($this->carUsage[$carData['cr_bl_carpurpose']]) ? $this->carUsage[$carData['cr_bl_carpurpose']] : '99',
            'loanAmt' => $carData['cr_principal_money'],
            'loanMonth' => $carData['cr_age'],
            'businessType' => 'BUS_001',//业务类型--固定为 按揭贷款
            'carStruct' => isset($this->carStruct[$carData['cr_constitute']]) ? $this->carStruct[$carData['cr_constitute']] : '',
            'isDualSign' => isset($this->Yorn[$carData['cr_bl_isdualsign']]) ? $this->Yorn[$carData['cr_bl_isdualsign']] : '',
        ];

        // 配偶
        if (!empty($carManMateData)) {
            $map['hasMate'] = 'Y';
            $map['mateInfo'] = [
                'name' => $carManMateData['cm_vip_name'],
                'certType' => '01',
                'certNo' => $carManMateData['cm_card'],
                'phone' => $carManMateData['cm_tel'],
            ];
            // 待处理
            $attachlistMateMan = [];
            $attacheListMT = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '配偶'])->select();
            if (!empty($attacheListMT)) {
                foreach ($attacheListMT as $key) {
                    $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);
                    $parms['requestSeqNo'] = $requestSeqNo;
                    $parms['itemCode'] = $itemCode;
                    $parms['companyCode'] = $companyCode;
                    $parms['orderNumber'] = '';
                    $attachmentType = '';
                    switch ($key['at_name']) {
                        case '身份证正面':
                            $attachmentType = 'matecardfront';
                            $parms['attachmentType'] = $attachmentType;
                            break;
                        case '身份证反面':
                            $attachmentType = 'matecardback';
                            $parms['attachmentType'] = $attachmentType;
                            break;
                        case '举拍照':
                            $attachmentType = 'mateface';
                            $parms['attachmentType'] = $attachmentType;
                            break;
                        default:
                            $parms = [];
                            break;
                    }

                    if (!empty($parms)) {
                        $parms['file'] = '@./'.$key['at_url'];
                        $parms['number'] = 0;

                        $rst = $this->picc_uploadimg_post(self::ATTACHMENT_API, $parms);
                        file_put_contents(LOG_PATH.'picc_uploadimg_send'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($parms).$rst. "\n\n" , FILE_APPEND);
                        $rst=json_decode($rst, true);
                        if($rst['success'] == 'Y') {
                            array_push($attachlistMateMan, $rst['atNumber']);
                        } else {
                            return $this->jsonReturns(false, '配偶' . $key['at_name'] . '上传失败');
                            //$this->error('消息：配偶' . $key['at_name'] . '上传失败');
                        }
                    }
                }
            }
            $map['mateInfo']['attachlist'] = $attachlistMateMan;
        } else {
            $map['hasMate'] = 'N';
            $map['mateInfo'] = ['name' => '','certType' => '','certNo' => '','phone' => '','attachlist' => ''];
        }

        // 担保人
        if (!empty($carManDBRData)) {
            if (count($carManDBRData) == 1) {
                $map['hasGuar1'] = 'Y';
                $map['guar1Info'] = [
                    'name' => $carManDBRData[0]['cm_vip_name'],
                    'certType' => '01',
                    'certNo' => $carManDBRData[0]['cm_card'],
                    'phone' => $carManDBRData[0]['cm_tel'],
                    'relation' => isset($this->relation[$carManDBRData[0]['cm_relation']]) ? $this->relation[$carManDBRData[0]['cm_relation']] : '99',
                    'attachlist' => [],
                ];

                $attachlistDBRMan = [];
                $attacheListMDBR = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '担保人'])->select();
                if (!empty($attacheListMDBR)) {
                    foreach ($attacheListMDBR as $key) {
                        $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);
                        $parms['requestSeqNo'] = $requestSeqNo;
                        $parms['itemCode'] = $itemCode;
                        $parms['companyCode'] = $companyCode;
                        $parms['orderNumber'] = '';
                        $attachmentType = '';
                        switch ($key['at_name']) {
                            case '身份证正面':
                                $attachmentType = 'guar1cardfront';
                                $parms['attachmentType'] = $attachmentType;
                                break;
                            case '身份证反面':
                                $attachmentType = 'guar1cardback';
                                $parms['attachmentType'] = $attachmentType;
                                break;
                            default:
                                $parms = [];
                                break;
                        }

                        if (!empty($parms)) {
                            $parms['file'] = '@./'.$key['at_url'];
                            $parms['number'] = 0;

                            $rst = $this->picc_uploadimg_post(self::ATTACHMENT_API, $parms);
                            file_put_contents(LOG_PATH.'picc_uploadimg_send'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($parms).$rst. "\n\n" , FILE_APPEND);
                            $rst=json_decode($rst, true);
                            if($rst['success'] == 'Y') {
                                array_push($attachlistDBRMan, $rst['atNumber']);
                            }  else {
                                return $this->jsonReturns(false, '担保人' . $key['at_name'] . '上传失败');
                                //$this->error('消息：担保人' . $key['at_name'] . '上传失败');
                            }
                        }
                    }
                }
                $map['guar1Info']['attachlist'] = $attachlistDBRMan;

                $map['hasGuar2'] = 'N';
                $map['guar2Info'] = ['name' => '','certType' => '','certNo' => '','phone' => '','attachlist' => '','relation' => ''];
            } elseif (count($carManDBRData) >= 2) {
                $map['hasGuar1'] = 'Y';
                $map['guar1Info'] = [
                    'name' => $carManDBRData[0]['cm_vip_name'],
                    'certType' => '01',
                    'certNo' => $carManDBRData[0]['cm_card'],
                    'phone' => $carManDBRData[0]['cm_tel'],
                    'relation' => isset($this->relation[$carManDBRData[0]['cm_relation']]) ? $this->relation[$carManDBRData[0]['cm_relation']] : '99',
                    'attachlist' => [],
                ];

                $map['hasGuar2'] = 'Y';
                $map['guar2Info'] = [
                    'name' => $carManDBRData[1]['cm_vip_name'],
                    'certType' => '01',
                    'certNo' => $carManDBRData[1]['cm_card'],
                    'phone' => $carManDBRData[1]['cm_tel'],
                    'relation' => isset($this->relation[$carManDBRData[1]['cm_relation']]) ? $this->relation[$carManDBRData[1]['cm_relation']] : '99',
                    'attachlist' => [],
                ];

                $attacheListMDBR2 = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '担保人', 'at_name' => '身份证正面照'])->select();
                $attacheListMDBR3 = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '担保人', 'at_name' => '身份证反面照'])->select();

                $dbr_f = [
                    [
                        'attachmentType' => 'guar1cardfront',
                        'file' => $attacheListMDBR2[0]['at_url'],
                        'number' => 0,
                    ],
                    [
                        'attachmentType' => 'guar1cardback',
                        'file' => $attacheListMDBR3[0]['at_url'],
                        'number' => 0,
                    ],
                    [
                        'attachmentType' => 'guar2cardfron',
                        'file' => $attacheListMDBR2[1]['at_url'],
                        'number' => 0,
                    ],
                    [
                        'attachmentType' => 'guar2cardback',
                        'file' => $attacheListMDBR3[1]['at_url'],
                        'number' => 0,
                    ],
                ];

                $dbrlistf1 = [];
                $dbrlistf2 = [];
                foreach ($dbr_f as $key => $vv) {
                    $vv['requestSeqNo'] = 'Picc' . $partnerCode . time() . rand(100000,999999);
                    $parms['itemCode'] = $itemCode;
                    $parms['companyCode'] = $companyCode;
                    $vv['orderNumber'] = '';
                    $rst = $this->picc_uploadimg_post(self::ATTACHMENT_API, $vv);
                    file_put_contents(LOG_PATH.'picc_uploadimg_send'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($vv).$rst. "\n\n" , FILE_APPEND);
                    $rst=json_decode($rst, true);
                    $attachmentType = '';
                    if($rst['success'] == 'Y') {
                        if ($vv['attachmentType'] == 'guar1cardfront' || $vv['attachmentType'] == 'guar1cardback') {
                            array_push($dbrlistf1, $rst['atNumber']);
                        } else {
                            array_push($dbrlistf2, $rst['atNumber']);
                        }
                    }  else {
                        return $this->jsonReturns(false, '担保人资料上传失败');
                        //$this->error('消息：担保人资料上传失败');
                    }
                }

                $map['guar1Info']['attachlist'] = $dbrlistf1;
                $map['guar2Info']['attachlist'] = $dbrlistf2;
            }

        } else {
            $map['hasGuar1'] = 'N';
            $map['guar1Info'] = ['name' => '','certType' => '','certNo' => '','phone' => '','attachlist' => '','relation' => ''];
            $map['hasGuar2'] = 'N';
            $map['guar2Info'] = ['name' => '','certType' => '','certNo' => '','phone' => '','attachlist' => '','relation' => ''];
        }

        file_put_contents(LOG_PATH.'ajax_data'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($map,true). "\n\n" , FILE_APPEND);

        //日期
        $now = time();
        //请求报文
//        echo"<pre/>";
//        var_dump($map);exit;
        $mapData['requestSeqNo'] = $requestSeqNo;//请求流水号
        $mapData['itemCode'] = $itemCode;//项目编号
        $mapData['companyCode'] = $companyCode;//子公司编号
        $mapData['interfaceCode']= 'AccessApply';//接口编号
        $mapData['interfaceVersion'] = 'v1';//接口版本号
        $mapData['infoContent'] = $this->encryptBody($map, $now);//加密报文内容
        $mapData['infoSign'] = $this->sign($mapData);//报文签名
        $url = self::BASE_URL;//请求地址
        $rst = $this->picc_http_post($url, urlencode(json_encode($mapData)));
        file_put_contents(LOG_PATH.'picc_customer_allow'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .$mapData.$rst. "\n\n" , FILE_APPEND);
        if($rst){
            $rst = json_decode(urldecode($rst), true);
            //var_dump($rst);
            $parseData = $this->parseResponse($rst);
            if (!$parseData['status']) {
                return $this->jsonReturns(false, $parseData['message']);
            }

            $finalData = $parseData['data'];
            if ($finalData['code'] == '00') {
                //将客户准入接口数据存入数据库中
                $model = M('PiccAllow');
                $answerdata = [
                    'number' => $number,
                    'code' => $finalData['code'],
                    'errorMsg' => $finalData['errorMsg'],
                    'orderNumber' => $finalData['orderNumber'],
                    'accessNumber' => $finalData['accessNumber'],
                ];
                $model->add($answerdata);
                return $this->jsonReturns(true, '接入人保准入接口成功');
            } else {
                //var_dump($finalData);
                //var_dump(str_replace("<br/>", "", $finalData['errorMsg']));
                file_put_contents(LOG_PATH.'ajax_data'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($finalData,true). "\n\n" , FILE_APPEND);
                return $this->jsonReturns(false, str_replace("<br/>", "", $finalData['errorMsg']));
            }
        } else {
            return $this->jsonReturns(false, '请求人保准入接口失败');
        }
    }

    /**
     * 对接宁波人保---核保申请接口---东海线上银行
     * add by llf 20190115
     * @parameters $url $parms
     * @return $data
     * */
    public function picc_customer_apply_dh($request)
    {
        $number = $request['number'];
//		$number = 'GH001-190123-002';
        //合作编号
        $partnerCode = C('NINGBO_PICC.ITEMCODE');
        //请求流水号(Picc+8位合作编号+Unix时间戳+6位序列号)
        $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);
        //项目编号
        $itemCode = C('NINGBO_PICC.ITEMCODE');
        //子公司编号
        $companyCode = C('NINGBO_PICC.COMPANYCODE');
        $mode = M('PiccAllow');
        $where = [
            'number' => $number,
            'code' => '00',
        ];
        //人保订单编号
        $result = $mode->where($where)->field('orderNumber')->find();
        $orderNumber = $result['orderNumber'];

        file_put_contents(LOG_PATH.'picc_customer_apply'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .$orderNumber. "\n\n" , FILE_APPEND);

        $map = [];
        $map['orderNumber'] = $orderNumber;

        // 根据订单号查询出主贷人的详细信息
        $carManData = M('CarMan')->where(['cm_number' => $number,'cm_type' => '购车人'])->find();
        $carManMateData = M('CarMan')->where(['cm_number' => $number,'cm_type' => '配偶'])->find();
        $carManDBRData = M('CarMan')->where(['cm_number' => $number,'cm_type' => '担保人'])->select();
        $carData = M('Car')->where(['cr_number' => $number])->find();

        // 根据订单号查询订单的风控总结
        $verifyData = M('Verify')->field('v_info')->where(['v_number' => $number, 'v_type' => '经理审核', 'v_status' => '通过'])->find();
        // 基本信息
        $map['baseInfo'] = [
            'branchCode' => '00111',//保险支公司代码
            'salerCode' => 'BJ001',//保险业务员代码
            'businessPlaceCode' => '330108',//业务发生地代码
            'remark' => '',//备注
            'loanBusinessType' => isset($this->loanBusinessType[$carData['cr_loanBusinessType']]) ? isset($this->loanBusinessType[$carData['cr_loanBusinessType']]) : '',//贷款业务类型
            'channelSalerName' => $carData['cr_channelSalerName'],//渠道业务员名称
            'channelSalerPhone' => $carData['cr_channelSalerPhone'],//渠道业务员手机号
        ];
        // 主贷人详情
        $emgTouchInfo = json_decode($carManData['cm_urgency_touch'], true);
        $map['mortgagorDetail'] = [
            'age' => (int)$carManData['cm_vip_age'],//年龄
            'sex' =>isset($this->sex[$carManData['cm_vip_sex']]) ? $this->sex[$carManData['cm_vip_sex']] : '',//性别
            'diploma' => isset($this->diploma[$carManData['cm_education']]) ? $this->diploma[$carManData['cm_education']] : '99',
            // 待处理
            'kosekiSSQCode' => $this->get_province_code($carManData['cm_koseki_county']),//户籍省市区代码
            'kosekiDetail' => $carManData['cm_kosekiDetail'],//户籍详细地址
            'isLocal' => isset($this->Yorn[$carManData['cm_islocal']]) ? $this->Yorn[$carManData['cm_islocal']] : '',
            'dwellSSQCode' => $this->get_province_code($carManData['cm_home_distinct']),//现住地址省市区代码
            'dwellDetail' => $carManData['cm_dwellDetail'],//现住详细地址
            'houseNature' => isset($this->houseNature[$carManData['cm_house_nature']]) ? $this->houseNature[$carManData['cm_house_nature']] : '',
            'hasHouseLoan' => isset($this->Yorn[$carManData['cm_has_houseloan']]) ? $this->Yorn[$carManData['cm_has_houseloan']] : '',
            'company' => $carManData['cm_company'],//工作单位
            'companyNature' => isset($this->companyNature[$carManData['cm_company_type']]) ? $this->companyNature[$carManData['cm_company_type']] : '',
            'companySSQCode' => $this->get_province_code($carManData['cm_company_country']),//单位地址省市区代码
            'companyDetail' => $carManData['cm_company_site'],//单位详细地址
            'companyTel' => $carManData['cm_company_tel'],//单位电话
            'workNature' => isset($this->workNature[$carManData['cm_work_nature']]) ? $this->workNature[$carManData['cm_work_nature']] : '99',
            'workCareer' => isset($this->workCareer[$carManData['cm_workCareer']]) ? $this->workCareer[$carManData['cm_workCareer']] : '18',
            'workDuty' => isset($this->workDuty[$carManData['cm_duty']]) ? $this->workDuty[$carManData['cm_duty']] : '99',
            'seniority' => $carManData['cm_seniority'],//工龄
            'mainIncome' => isset($this->mainIncome[$carManData['cm_income_from']]) ? $this->mainIncome[$carManData['cm_income_from']] : '99',
            'monthIncome' => (int)$carManData['cm_income'],//月收入
            'hasSocialSecurity' => isset($this->Yorn[$carManData['cm_social_security']]) ? $this->Yorn[$carManData['cm_social_security']] : '',
            'emgTouchName1' => isset($emgTouchInfo[0]['urgency_touch']) ? $emgTouchInfo[0]['urgency_touch'] : '',//紧急联系人一姓名
            'emgTouchPhone1' => isset($emgTouchInfo[0]['tel']) ? $emgTouchInfo[0]['tel'] : '',//紧急联系人一手机号
            'emgTouchRel1' =>  isset($emgTouchInfo[0]['filiation']) ? (isset($this->relation[$emgTouchInfo[0]['filiation']]) ? $this->relation[$emgTouchInfo[0]['filiation']] : '99') : '',
            'emgTouchName2' => isset($emgTouchInfo[1]['urgency_touch']) ? $emgTouchInfo[1]['urgency_touch'] : '',//紧急联系人二姓名
            'emgTouchPhone2' => isset($emgTouchInfo[1]['tel']) ? $emgTouchInfo[1]['tel'] : '',//紧急联系人二手机号
            'emgTouchRel2' => isset($emgTouchInfo[1]['filiation']) ? (isset($this->relation[$emgTouchInfo[1]['filiation']]) ? $this->relation[$emgTouchInfo[1]['filiation']] : '99') : '',
            'dwellTel' => $carManData['cm_dwell_tel'],//现住地址电话
            'housePropertyType' => isset($this->housePropertyType[$carManData['cm_housePropertyType']]) ? $this->housePropertyType[$carManData['cm_housePropertyType']] : '99',//房产类型
            'postSSQCode' => '',//邮寄地址省市区代码
            'postDetail' => '',//邮寄详细地址
            'postCode' => $carManData['cm_postCode'],//邮编
            'degree' => isset($this->degree[$carManData['cm_degree']]) ? $this->degree[$carManData['cm_degree']] : '',//学位
            'workClass' => isset($this->workClass[$carManData['cm_workClass']]) ? $this->workClass[$carManData['cm_workClass']] : '',//职业分类
            'workTitle' => isset($this->workTitle[$carManData['cm_workTitle']]) ? $this->workTitle[$carManData['cm_workTitle']] : '',//工作职称
            'driveLicenseStatus' => '',//驾照情况
            'isFarmer' => '',//是否农户
            'companyPostCode' => '',//公司邮编
            'entryDate' => $carManData['cm_entry_date'],//入职时间
            'yearIncome' => $carManData['cm_yearIncome'],//年收入
            'familyYearIncome' => $carManData['cm_familyYearIncome'],//家庭年收入
            'enterpriseName' => '',//经营企业名称
        ];

        // 配偶详情
        if (!empty($carManMateData)) {
            $map['mateDetail'] = [
                'age' => (int)$carManMateData['cm_vip_age'],//年龄
                'company' => $carManMateData['cm_company'],//工作单位
                'workDuty' => isset($this->workDuty[$carManMateData['cm_duty']]) ? $this->workDuty[$carManMateData['cm_duty']] : '99',
                'mainIncome' => isset($this->mainIncome[$carManMateData['cm_income_from']]) ? $this->mainIncome[$carManMateData['cm_income_from']] : '99',
                'monthIncome' => (int)$carManMateData['cm_income'],//月收入
            ];
        } else {
            $map['mateDetail'] = ['age' => '', 'company' => '', 'workDuty' => '', 'mainIncome' => '', 'monthIncome' => ''];
        }

        // 担保人详情
        if (!empty($carManDBRData)) {
            if (count($carManDBRData) == 1) {
                $map['guar1Detail'] = [
                    'age' => (int)$carManDBRData[0]['cm_vip_age'],//年龄
                    'company' => $carManDBRData[0]['cm_company'],//工作单位
                    'workDuty' => isset($this->workDuty[$carManDBRData[0]['cm_duty']]) ? $this->workDuty[$carManDBRData[0]['cm_duty']] : '99',
                    'mainIncome' => isset($this->mainIncome[$carManDBRData[0]['cm_income_from']]) ? $this->mainIncome[$carManDBRData[0]['cm_income_from']] : '99',
                    'monthIncome' => (int)$carManDBRData[0]['cm_income'],//月收入
                    'dwellSSQCode' => $this->get_province_code($carManData['cm_home_distinct']),//现住地址省市区代码
                    'dwellDetail' => $carManData['cm_dwellDetail'],//现住详细地址
                ];
                $map['guar2Detail'] = ['age' => '', 'company' => '', 'workDuty' => '', 'mainIncome' => '', 'monthIncome' => ''];
            } elseif (count($carManDBRData) >= 2) {
                $map['guar1Detail'] = [
                    'age' => (int)$carManDBRData[0]['cm_vip_age'],//年龄
                    'company' => $carManDBRData[0]['cm_company'],//工作单位
                    'workDuty' => isset($this->workDuty[$carManDBRData[0]['cm_duty']]) ? $this->workDuty[$carManDBRData[0]['cm_duty']] : '99',
                    'mainIncome' => isset($this->mainIncome[$carManDBRData[0]['cm_income_from']]) ? $this->mainIncome[$carManDBRData[0]['cm_income_from']] : '99',
                    'monthIncome' => (int)$carManDBRData[0]['cm_income'],//月收入
                    'dwellSSQCode' => $this->get_province_code($carManData['cm_home_distinct']),//现住地址省市区代码
                    'dwellDetail' => $carManData['cm_dwellDetail'],//现住详细地址
                ];

                $map['guar2Detail'] = [
                    'age' => (int)$carManDBRData[1]['cm_vip_age'],//年龄
                    'company' => $carManDBRData[1]['cm_company'],//工作单位
                    'workDuty' => isset($this->workDuty[$carManDBRData[1]['cm_duty']]) ? $this->workDuty[$carManDBRData[1]['cm_duty']] : '99',
                    'mainIncome' => isset($this->mainIncome[$carManDBRData[1]['cm_income_from']]) ? $this->mainIncome[$carManDBRData[1]['cm_income_from']] : '99',
                    'monthIncome' => (int)$carManDBRData[1]['cm_income'],//月收入
                    'dwellSSQCode' => $this->get_province_code($carManData['cm_home_distinct']),//现住地址省市区代码
                    'dwellDetail' => $carManData['cm_dwellDetail'],//现住详细地址
                ];
            }

        } else {
            $map['guar1Detail'] = ['age' => '', 'company' => '', 'workDuty' => '', 'mainIncome' => '', 'monthIncome' => ''];
            $map['guar2Detail'] = ['age' => '', 'company' => '', 'workDuty' => '', 'mainIncome' => '', 'monthIncome' => ''];
        }

        // 车辆详情
        $map['carDetail'] = [
            'carType' => isset($this->carType[$carData['cr_type']]) ? $this->carType[$carData['cr_type']] : '',
            'carClass' => isset($this->carClass[$carData['cr_classs']]) ? $this->carClass[$carData['cr_classs']] : '',
            'carBrand' => $carData['cr_brand'],//车辆品牌
            'carSeries' => $carData['cr_series'],//车辆车系
            'carSculpt' => $carData['cr_model'],//车辆车型
            'powerCteType' => isset($this->powerCteType[$carData['cr_powertype']]) ? $this->powerCteType[$carData['cr_powertype']] : '',//动力系统类别
            'isCompanyLic' => isset($this->Yorn[$carData['cr_is_board']]) ? $this->Yorn[$carData['cr_is_board']] : '',
            'mortgageeType' => isset($this->mortgageeType[$carData['cr_mortgagetype']]) ? $this->mortgageeType[$carData['cr_mortgagetype']] : '',
            'mortgageeName' => $carData['cr_mortgageeName'],//抵押人姓名
            'mortgageeRelate' => isset($this->mortgageeRelate[$carData['cr_mortgageeRelate']]) ? $this->mortgageeRelate[$carData['cr_mortgageeRelate']] : '',//抵押人与借贷人关系
            'carPrice' => $carData['cr_money'],//车价
            'carSuggestPrice' => ($carData['cr_price'] == '' ? 0 : ((float)($carData['cr_price'])))*10000,//厂商指导价
            'licInstallSSQCode' => $this->get_province_code($carData['cr_board_city']),//上牌地
            'driverLicBelong' => $carData['cr_owner'],//行驶证车主
            'sculptCode' => $carData['cr_sculptcode'],//车型代码
            'carColor' => isset($this->carColor[$carData['cr_carcolor']]) ? $this->carColor[$carData['cr_carcolor']] : '',
            'engineNumber' => $carData['cr_engineno'],//发动机编号
            'recordDate' => $carData['cr_recorddate'],//登记日期
            'displace' => $carData['cr_displace'],//排量
            'vin' => $carData['cr_vin'],//车架号
            'serviceLife' => $carData['cr_servicelife'],//使用年限
            'miles' => $carData['cr_miles'],//里程数
            'valuate' => $carData['cr_valuate'],//评估价
            'licNumber' => $carData['cr_licnumber'],//车牌号
            'licBelongSSQCode' => $this->get_province_code($carData['cr_licBelong_country']),//车牌归属地省市区代码
            'licInstall' => $carData['cr_owner'],//上牌所有者(租金分期直租业务必填)
            'invoiceNumber' => $carData['cr_invoiceno'],//发票号
            'invoiceIssueEnity' => $carData['cr_invoiceissueenity'],//发票开具单位
            'carManufacturer' => '',//车辆制造商
            'carUse' => isset($this->carUse[$carData['cr_carUse']]) ? $this->carUse[$carData['cr_carUse']] : '',//车辆用途
            'licenseType' => isset($this->licenseType[$carData['cr_licenseType']]) ? $this->licenseType[$carData['cr_licenseType']] : '',//车牌类型
            'transferRecordDate' => $carData['cr_transferRecordDate'],//转移登记日期
            'seatCount' => $carData['cr_seat'],//载客
        ];

        // 融资详情
        $map['advanceDetail'] = [
            'loanAmt' => $carData['cr_bl_loanmoney'],//贷款本金
            'loanMonth' => $carData['cr_age'],//贷款期数
            'repayType' => '01',//还款方式固定为--等额本息
            'repayRate' => '01',//还款频率固定为--月
            'contractPrice' => $carData['cr_principal_money'],//合同价
            'netPrice' => $carData['cr_bl_netprice'],//车辆净价格
            'coverage' => $carData['cr_bl_insurance'],//保额
            'rate' => $carData['cr_bl_rate'],//保费费率
            'serviceFee' => $carData['cr_service_charge'],//服务费
            'downPayment' => $carData['cr_bl_firstmoney'],//首付金额
            'downPayRate' => $carData['cr_bl_firstpercent'] * 100,//首付比例
            'loanRate' => $carData['cr_tb_rate'],//贷款利率
            'loanStartDate' => '',//贷款期限起期
            'loanEndDate' => '',//贷款期限止期
        ];

        //租赁详情
        $map['rentDetail'] = [
            'rentMonth' => $carData['cr_rentMonth'],//租赁期限
            'rentMonthMoney' => $carData['cr_bankRent'],//每月租金
            'rentSum' => $carData['cr_rentSum'],//租金总额
            'firstRentPay' => $carData['cr_firstRentPay'],//首付租金
            'purchaseTax' => $carData['cr_buy_fate'],//购置税
            'commercialInsurance' => $carData['cr_commercialInsurance'],//商业险
            'compulsoryInsurance' => $carData['cr_compulsoryInsurance'],//交强险
            'otherInsurance' => $carData['cr_otherInsurance'],//其他险种
        ];

        //风控总结
        $map['riskSummarize']  = isset($verifyData['v_info']) ? $verifyData['v_info'] : '通过';
        //附件列表
        $map['attachlist'] = [];

        // 资料信息先行(1必传0非必传)
        $mainATF = [
            '借款人-驾驶证' => ['loanerdrivinglicense', 1, 1],//主贷人驾驶证
            '借款人-结离婚证或单身证明' => ['loanermaritalcert', 1, 0],//主贷人结婚证/离婚证
            '借款人-征信报告(个人、企业)' => ['loanercreditreport', 1, 0],//主贷人征信报告
            '借款人-户口本' => ['loanerkosekidocument', 4, 1],//主贷人户籍资料
            '借款人-房产证、居住证或暂住证' => ['loanerhousedocument', 8, 0],
            '借款人-收入证明' => ['loanerincomecert', 1, 1],//主贷人收入证明
            '借款人-银行流水' => ['loaneraccountstatement', 8, 1],//主贷人银行流水
            '借款人-企业资料' => ['loanercompanydocument', 4, 0],//主贷人企业资料
            '借款人-保险6单' => ['piccdocument', 16, 1],//人保6单

            '配偶-征信报告(个人、企业)' => ['matecreditreport', 1, 0],//配偶征信报告
            '配偶-银行流水' => ['mateaccountstatement', 8, 0],//配偶银行流水

            '房屋小区大门或村镇标记牌' => ['estatedoor', 1, 0],//小区大门或村镇标记牌
            '房屋门牌号或全景' => ['doornumber', 1, 0],//房屋门牌号或全景
            '借款人与家访人员合照' => ['customerandvistor', 1, 0],//客户与家访员合照
            //'房屋客厅、卧室、厨房、卫生间' => ['', 2],//客厅

            '车头照' => ['carexterior', 4, 0],//车辆外观照（前后左右）
            '车架号' => ['carvin', 1, 0],//车架号
            '后备箱' => ['cartrunk', 1, 0],//后备箱
            '仪表盘' => ['cardashboard', 1, 0],//仪表盘
            '出厂铭牌' => ['carnameplate', 1, 0],//出厂铭牌
            '内部前、后座位' => ['carseats', 4, 0],//内部前后座位
            '行驶证' => ['cardrivinglicense', 1, 0],//行驶证
            '登记证' => ['carregistercert', 1, 0],//登记证
            '车辆与借款人及家访人员合照' => ['carandcustomerandvistor', 1, 0],//车辆、主贷人、家访员合照
            '验车人与抵押车合影' => ['carandchecker', 1, 0],//验车人与车辆合照
            '车辆评估报告' => ['carassessreport', 1, 0],//车辆评估报告
            '购车发票' => ['carinvoicepurchase', 1, 0],//购车发票
        ];

        $atf_data = [];
        foreach ($mainATF as $atfk => $atfv) {
            $tempatf = [];
            $num = $atfv[1];
            $n = $atfv[2];//add by llf 20190304
            $attaData = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_classify' => $atfk])->select();
            if (!empty($attaData)) {
                $trueNum = count($attaData) > $num ? $num : count($attaData);
                for ($i = 0; $i < $trueNum; $i++) {
                    $tempatf['itemCode'] = $partnerCode;
                    $tempatf['orderNumber'] = $orderNumber;
                    $tempatf['attachmentType'] = $atfv[0];
                    $tempatf['companyCode'] = $companyCode;
                    $tempatf['file'] = '@./'.$attaData[$i]['at_url'];
                    $tempatf['number'] = $i;
                    $tempatf['name'] = $atfk;
                }
            }

            //判断是否必传 add by llf 20190304
            if($n == 1 && empty($attaData)){
                return $this->jsonReturns(false,  $atfk . '资料必须上传!');
            }

            if (!empty($tempatf)) {
                $atf_data[] = $tempatf;
            }
        }


        // 发送文件信息
        $finalAttList = [];
        if (!empty($atf_data)) {
            foreach ($atf_data as $atf) {
                $name = $atf['name'];
                unset($atf['name']);
                $atf['requestSeqNo'] = 'Picc' . $partnerCode . time() . rand(100000,999999);
                $rst = $this->picc_uploadimg_post(self::ATTACHMENT_API, $atf);
//                file_put_contents(LOG_PATH.'picc_uploadimg_send'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($vv).$rst. "\n\n" , FILE_APPEND);
                $rst=json_decode($rst, true);
                if($rst['success'] == 'Y') {
//                	array_push($finalAttList, $atf['attachmentType']);
                    array_push($finalAttList, $rst['atNumber']);
                }  else {
//                	var_dump($rst);exit;
//                	return $this->jsonReturns(false, str_replace("<br/>", "", $finalData['errorMsg']));
                    return $this->jsonReturns(false, '存在【'.$name.'】资料上传失败');
                }
            }
        }

        $map['attachlist'] = $finalAttList;

        file_put_contents(LOG_PATH.'picc_customer_apply_map'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($map,true). "\n\n" , FILE_APPEND);

        $mapData['requestSeqNo'] = $requestSeqNo;//请求流水号
        $mapData['itemCode'] = $itemCode;//项目编号
        $mapData['companyCode'] = $companyCode;//子公司编号
        $mapData['interfaceCode']= 'UnderWriteApply';//接口编号
        $mapData['interfaceVersion'] = 'v1';//接口版本号
        $mapData['infoContent'] = $this->encryptBody($map, time());//加密报文内容
        $mapData['infoSign'] = $this->sign($mapData);//报文签名

//		var_dump($mapData);exit;
        $url = self::BASE_URL;//请求地址
        $rst = $this->picc_http_post($url, urlencode(json_encode($mapData)));
        file_put_contents(LOG_PATH.'picc_customer_apply'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .$mapData.$rst. "\n\n" , FILE_APPEND);
        //将核保申请接口返回的数据存入数据表
        if($rst){
            $rst = json_decode(urldecode($rst), true);
//			var_dump($rst);exit;
            $parseData = $this->parseResponse($rst);
            if (!$parseData['status']) {
                return $this->jsonReturns(false, $parseData['message']);
            }
            file_put_contents(LOG_PATH.'ajax_data'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($parseData,256). "\n\n" , FILE_APPEND);

            $finalData = $parseData['data'];
            if ($finalData['code'] == '00' || $finalData['code'] == '03') {
                $pamode = M('PiccApplyAnswer');
                $data = [
                    'number' => $number,
                    'code' => $finalData['code'],
                    'errorMsg' => $finalData['errorMsg'],
                    'underWriteNumber' => $finalData['underWriteNumber'],
                    'checkResult' => json_encode($finalData['checkResult'], 256),
                ];
                $pamode->add($data);
                return $this->jsonReturns(true, '接入人保核保申请接口成功');
            } else {
                /*var_dump($finalData);
                var_dump(str_replace("<br/>", "", $finalData['errorMsg']));*/
                file_put_contents(LOG_PATH.'ajax_data'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($finalData,256). "\n\n" , FILE_APPEND);
                return $this->jsonReturns(false, str_replace("<br/>", "", $finalData['errorMsg']));
            }
        } else {
//        	file_put_contents(LOG_PATH.'ajax_data'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($finalData,256). "\n\n" , FILE_APPEND);
            return $this->jsonReturns(false, '请求人保核保申请接口失败');
        }
    }


    /**
     * 对接宁波人保---核保审核结果通知接口---东海线上银行
     * add by llf 20190118
     * @parameters $url $parms
     * @return $data
     * */
    public function picc_apply_answer_dh(){
        $input = file_get_contents('php://input');
//      file_put_contents(LOG_PATH.'piccback'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($input,256). "\n\n" , FILE_APPEND);
        $requestData = json_decode(urldecode($input), true);

//      file_put_contents(LOG_PATH.'piccback'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($requestData,256). "\n\n" , FILE_APPEND);

        $parseData = $this->parseResponse($requestData);
//      file_put_contents(LOG_PATH.'piccback'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($parseData,256). "\n\n" , FILE_APPEND);
        if (!$parseData['status']) {
            unset($requestData['infoContent']);
            unset($requestData['infoSign']);
            $result = $this->jsonReturns(false, '');
            $map['success'] = 'N';

            $requestData['respCode'] = 'E';
            $requestData['respMsg'] = $result['message'];
            $requestData['infoContent'] = $this->encryptBody($map, time());
            $requestData['infoSign'] = $this->sign($requestData);
            file_put_contents(LOG_PATH.'piccback1028'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($requestData,256). "\n\n" , FILE_APPEND);
            exit(urlencode(json_encode($requestData)));
        }

        $finalData = $parseData['data'];

        $uwinfo = M('PiccApplyAnswer')->field('number')->where(['underWriteNumber' => $finalData['underWriteNumber']])->find();
        // 核保申请编号(通过核保申请接口获取)
        $number = $uwinfo['number'];

        $aduitResult = $finalData['aduitResult'];
        if ($aduitResult == '00') {
            $v_status = '通过';
            $v_result = "审核通过";
            $status = '终审通过';
        } elseif ($aduitResult == '01') {
            $v_status = '退单';
            $v_result = "审核不通过";
            $status = '初审提交';
        } elseif ($aduitResult == '02') {
            $v_status = '退回';
            $v_result = "资料错误";
            $status = '初审提交';
        }

        $saveData = [
            'v_number' => $number,
            'v_type' => '核保审核',
            'v_status' => $v_status,
            'v_result' => $v_result,
            'v_info' => $finalData['aduitOpinion'],
            'v_view' => '',
            'v_uid' => 0,
            'v_user' => '人保审核',
            'v_time' => time(),
            'v_is_quit' => 1,
            'v_duty_rate' => $finalData['riskRate'],
            'v_fee_rate' => $finalData['rate'],
            'v_highest_loan' => $finalData['maxLoanAmt'],
        ];

        $v_where['v_status'] = '正常';
        $v_where['v_number'] = $number;
        $v_where['v_type'] = '核保审核';
        $v_data = M('Verify') -> where($v_where)-> find();
        if($v_data){
            $v_id = M('Verify')->where($v_where)->save($saveData);
        }else{
            $v_id = M('Verify')->add($saveData);
        }

        M('Order')->where(['o_number' => $number])->save(['o_status' => $status]);

        unset($requestData['infoContent']);
        unset($requestData['infoSign']);


        $map['success'] = 'Y';

        $requestData['respCode'] = 'S';
        $requestData['respMsg'] = '成功';
        $requestData['infoContent'] = $this->encryptBody($map, time());
        $requestData['infoSign'] = $this->sign($requestData);

        file_put_contents(LOG_PATH.'piccback1024'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($requestData,256). "\n\n" , FILE_APPEND);
        exit(urlencode(json_encode($requestData)));
    }

    /**
     * 对接宁波人保---车辆信息补录接口--东海银行
     * add by llf 20190116
     * @parameters $url $parms
     * @return $data
     * */
    public function picc_carinfo_add_dh($request){
        $number = $request['number'];
        $carData = M('Car')->where(['cr_number' => $number])->find();
        //合作编号
        $partnerCode = C('NINGBO_PICC.ITEMCODE');
        //项目编号
        $itemCode = C('NINGBO_PICC.ITEMCODE');
        //子公司编号
        $companyCode = C('NINGBO_PICC.COMPANYCODE');
        //请求流水号(Picc+8位合作编号+Unix时间戳+6位序列号)
        $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);
        $mode = M('PiccAllow');
        $where = [
            'number' => $number,
            'code' => '00',
        ];
        //人保订单编号
        $result = $mode->where($where)->field('orderNumber')->find();
        $orderNumber = $result['orderNumber'];

        //车辆信息补录数据
        $data = [
            //人保订单编号
            'orderNumber' => $orderNumber,
            //补录详情
            'addDetail' => [
                'sculptCode' => $carData['cr_sculptcode'],//车型代码
                'carColor' => isset($this->carColor[$carData['cr_carcolor']]) ? $this->carColor[$carData['cr_carcolor']] : '',
                'engineNumber' => $carData['cr_engineno'],//发动机编号
                'recordDate' => '',//登记日期
                'displace' => $carData['cr_displace'],//排量
                'vin' => $carData['cr_vin'],//车架号
                'serviceLife' => '',//使用年限
                'miles' => '',//里程数
                'valuate' => '',//评估价
                'licNumber' => '',//车牌号
                'licBelongSSQCode' => '',//车牌归属地省市区代码
                'licInstall' => '',//上牌所有者
                'invoiceNumber' => '',//发票号
                'invoiceIssueEnity' => '',//发票开具单位
                'carManufacturer' => '',//车辆制造商
                'transferRecordDate' => '',//转移登记日期
            ],
        ];

        //请求报文
        $parms['requestSeqNo'] = $requestSeqNo;//请求流水号
        $parms['itemCode'] = $itemCode;//项目编号
        $parms['companyCode'] = $companyCode;//子公司编号
        $parms['interfaceCode']= 'AdditionalRecordApply';//接口编号
        $parms['interfaceVersion'] = 'v1';//接口版本号
        $parms['infoContent'] = $this->encryptBody($data, time());//加密报文内容
        $parms['infoSign'] = $this->sign($parms);//报文签名

        $url = self::BASE_URL;//请求地址
        $rst = $this->picc_http_post($url, urlencode(json_encode($parms)));
        file_put_contents(LOG_PATH.'picc_carinfo_add'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .$parms.$rst. "\n\n" , FILE_APPEND);

        if($rst){
            $rst = json_decode(urldecode($rst), true);
            $parseData = $this->parseResponse($rst);
            if (!$parseData['status']) {
                return $this->jsonReturns(false, $parseData['message']);
            }

            $finalData = $parseData['data'];
            if ($finalData['code'] == '00') {
                return $this->jsonReturns(true, '接入人保车辆信息补录接口成功');
            } else {
                return $this->jsonReturns(false, str_replace("<br/>", "", $finalData['errorMsg']));
            }
        } else {
            return $this->jsonReturns(false, '请求人保车辆信息补录接口失败');
        }
    }

    /**
     * 对接宁波人保---补录关系人接口
     * add by llf 20190326
     * @parameters $url $parms
     * @return $data
     * */
    public function picc_relation_add_dh($request){
        $number = $request['number'];
        //合作编号
        $partnerCode = C('NINGBO_PICC.ITEMCODE');
        //项目编号
        $itemCode = C('NINGBO_PICC.ITEMCODE');
        //子公司编号
        $companyCode = C('NINGBO_PICC.COMPANYCODE');
        //请求流水号(Picc+8位合作编号+Unix时间戳+6位序列号)
        $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);
        $where = [
            'number' => $number,
            'code' => '00',
        ];
        //人保订单编号
        $map = [];
        $result = M('PiccAllow')->where($where)->field('orderNumber')->find();
        $map['orderNumber'] = $result['orderNumber'];
        //配偶信息
        $carManMateData = M('CarMan')->where(['cm_number' => $number,'cm_type' => '配偶'])->find();
        //担保人信息
        $carManDBRData = M('CarMan')->where(['cm_number' => $number,'cm_type' => '担保人'])->select();
        // 配偶
        if (!empty($carManMateData)) {
            $map['hasMate'] = 'Y';
            $map['mateInfo'] = [
                'name' => $carManMateData['cm_vip_name'],
                'certType' => '01',
                'certNo' => $carManMateData['cm_card'],
                'phone' => $carManMateData['cm_tel'],
            ];
            //附件列表
            $attachlistMateMan = [];
            $attacheListMT = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '配偶'])->select();
            if (!empty($attacheListMT)) {
                foreach ($attacheListMT as $key) {
                    $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);
                    $parms['requestSeqNo'] = $requestSeqNo;
                    $parms['itemCode'] = $itemCode;
                    $parms['companyCode'] = $companyCode;
                    $parms['orderNumber'] = '';
                    switch ($key['at_name']) {
                        case '身份证正面':
                            $attachmentType = 'matecardfront';
                            $parms['attachmentType'] = $attachmentType;
                            break;
                        case '身份证反面':
                            $attachmentType = 'matecardback';
                            $parms['attachmentType'] = $attachmentType;
                            break;
                        case '举拍照':
                            $attachmentType = 'mateface';
                            $parms['attachmentType'] = $attachmentType;
                            break;
                        default:
                            $parms = [];
                            break;
                    }

                    if (!empty($parms)) {
                        $parms['file'] = '@./'.$key['at_url'];
                        $parms['number'] = 0;

                        $rst = $this->picc_uploadimg_post(self::ATTACHMENT_API, $parms);
                        file_put_contents(LOG_PATH.'picc_uploadimg_send'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($parms).$rst. "\n\n" , FILE_APPEND);
                        $rst=json_decode($rst, true);
                        if($rst['success'] == 'Y') {
                            array_push($attachlistMateMan, $rst['atNumber']);
                        } else {
                            return $this->jsonReturns(false, '配偶' . $key['at_name'] . '上传失败');
                            //$this->error('消息：配偶' . $key['at_name'] . '上传失败');
                        }
                    }
                }
            }
            $map['mateInfo']['attachlist'] = $attachlistMateMan;
        } else {
            $map['hasMate'] = 'N';
            $map['mateInfo'] = ['name' => '','certType' => '','certNo' => '','phone' => '','attachlist' => ''];
        }
        // 担保人
        if (!empty($carManDBRData)) {
            if (count($carManDBRData) == 1) {
                $map['hasGuar1'] = 'Y';
                $map['guar1Info'] = [
                    'name' => $carManDBRData[0]['cm_vip_name'],
                    'certType' => '01',
                    'certNo' => $carManDBRData[0]['cm_card'],
                    'phone' => $carManDBRData[0]['cm_tel'],
                    'relation' => isset($this->relation[$carManDBRData[0]['cm_relation']]) ? $this->relation[$carManDBRData[0]['cm_relation']] : '99',
                    'attachlist' => [],
                ];

                $attachlistDBRMan = [];
                $attacheListMDBR = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '担保人'])->select();
                if (!empty($attacheListMDBR)) {
                    foreach ($attacheListMDBR as $key) {
                        $requestSeqNo = 'Picc' . $partnerCode . time() . rand(100000,999999);
                        $parms['requestSeqNo'] = $requestSeqNo;
                        $parms['itemCode'] = $itemCode;
                        $parms['companyCode'] = $companyCode;
                        $parms['orderNumber'] = '';
                        $attachmentType = '';
                        switch ($key['at_name']) {
                            case '身份证正面':
                                $attachmentType = 'guar1cardfront';
                                $parms['attachmentType'] = $attachmentType;
                                break;
                            case '身份证反面':
                                $attachmentType = 'guar1cardback';
                                $parms['attachmentType'] = $attachmentType;
                                break;
                            default:
                                $parms = [];
                                break;
                        }

                        if (!empty($parms)) {
                            $parms['file'] = '@./'.$key['at_url'];
                            $parms['number'] = 0;

                            $rst = $this->picc_uploadimg_post(self::ATTACHMENT_API, $parms);
                            file_put_contents(LOG_PATH.'picc_uploadimg_send'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($parms).$rst. "\n\n" , FILE_APPEND);
                            $rst=json_decode($rst, true);
                            if($rst['success'] == 'Y') {
                                array_push($attachlistDBRMan, $rst['atNumber']);
                            }  else {
                                return $this->jsonReturns(false, '担保人' . $key['at_name'] . '上传失败');
                                //$this->error('消息：担保人' . $key['at_name'] . '上传失败');
                            }
                        }
                    }
                }
                $map['guar1Info']['attachlist'] = $attachlistDBRMan;

                $map['hasGuar2'] = 'N';
                $map['guar2Info'] = ['name' => '','certType' => '','certNo' => '','phone' => '','attachlist' => '','relation' => ''];
            } elseif (count($carManDBRData) >= 2) {
                $map['hasGuar1'] = 'Y';
                $map['guar1Info'] = [
                    'name' => $carManDBRData[0]['cm_vip_name'],
                    'certType' => '01',
                    'certNo' => $carManDBRData[0]['cm_card'],
                    'phone' => $carManDBRData[0]['cm_tel'],
                    'relation' => isset($this->relation[$carManDBRData[0]['cm_relation']]) ? $this->relation[$carManDBRData[0]['cm_relation']] : '99',
                    'attachlist' => [],
                ];

                $map['hasGuar2'] = 'Y';
                $map['guar2Info'] = [
                    'name' => $carManDBRData[1]['cm_vip_name'],
                    'certType' => '01',
                    'certNo' => $carManDBRData[1]['cm_card'],
                    'phone' => $carManDBRData[1]['cm_tel'],
                    'relation' => isset($this->relation[$carManDBRData[1]['cm_relation']]) ? $this->relation[$carManDBRData[1]['cm_relation']] : '99',
                    'attachlist' => [],
                ];

                $attacheListMDBR2 = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '担保人', 'at_name' => '身份证正面照'])->select();
                $attacheListMDBR3 = M('Attachment')->where(['at_number' => $number, 'at_statsus' => 'ok', 'at_viptype' => '担保人', 'at_name' => '身份证反面照'])->select();

                $dbr_f = [
                    [
                        'attachmentType' => 'guar1cardfront',
                        'file' => $attacheListMDBR2[0]['at_url'],
                        'number' => 0,
                    ],
                    [
                        'attachmentType' => 'guar1cardback',
                        'file' => $attacheListMDBR3[0]['at_url'],
                        'number' => 0,
                    ],
                    [
                        'attachmentType' => 'guar2cardfron',
                        'file' => $attacheListMDBR2[1]['at_url'],
                        'number' => 0,
                    ],
                    [
                        'attachmentType' => 'guar2cardback',
                        'file' => $attacheListMDBR3[1]['at_url'],
                        'number' => 0,
                    ],
                ];

                $dbrlistf1 = [];
                $dbrlistf2 = [];
                foreach ($dbr_f as $key => $vv) {
                    $vv['requestSeqNo'] = 'Picc' . $partnerCode . time() . rand(100000,999999);
                    $parms['itemCode'] = $itemCode;
                    $parms['companyCode'] = $companyCode;
                    $vv['orderNumber'] = '';
                    $rst = $this->picc_uploadimg_post(self::ATTACHMENT_API, $vv);
                    file_put_contents(LOG_PATH.'picc_uploadimg_send'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .json_encode($vv).$rst. "\n\n" , FILE_APPEND);
                    $rst=json_decode($rst, true);
                    $attachmentType = '';
                    if($rst['success'] == 'Y') {
                        if ($vv['attachmentType'] == 'guar1cardfront' || $vv['attachmentType'] == 'guar1cardback') {
                            array_push($dbrlistf1, $rst['atNumber']);
                        } else {
                            array_push($dbrlistf2, $rst['atNumber']);
                        }
                    }  else {
                        return $this->jsonReturns(false, '担保人资料上传失败');
                        //$this->error('消息：担保人资料上传失败');
                    }
                }

                $map['guar1Info']['attachlist'] = $dbrlistf1;
                $map['guar2Info']['attachlist'] = $dbrlistf2;
            }

        } else {
            $map['hasGuar1'] = 'N';
            $map['guar1Info'] = ['name' => '','certType' => '','certNo' => '','phone' => '','attachlist' => '','relation' => ''];
            $map['hasGuar2'] = 'N';
            $map['guar2Info'] = ['name' => '','certType' => '','certNo' => '','phone' => '','attachlist' => '','relation' => ''];
        }
        //请求报文
        $mapdata['requestSeqNo'] = $requestSeqNo;//请求流水号
        $mapdata['itemCode'] = $itemCode;//项目编号
        $mapdata['companyCode'] = $companyCode;//子公司编号
        $mapdata['interfaceCode']= 'AddRelation';//接口编号
        $mapdata['interfaceVersion'] = 'v1';//接口版本号
        $mapdata['infoContent'] = $this->encryptBody($map, time());//加密报文内容
        $mapdata['infoSign'] = $this->sign($mapdata);//报文签名

        $url = self::BASE_URL;//请求地址
        $rst = $this->picc_http_post($url, urlencode(json_encode($mapdata)));
        file_put_contents(LOG_PATH.'picc_relation_add'. date('Ymd') .'.log', date('Y-m-d H:i:s') . "\t" .$mapdata.$rst. "\n\n" , FILE_APPEND);

        if($rst){
            $rst = json_decode(urldecode($rst), true);
            $parseData = $this->parseResponse($rst);
            if (!$parseData['status']) {
                return $this->jsonReturns(false, $parseData['message']);
            }

            $finalData = $parseData['data'];
            if ($finalData['code'] == '00') {
                return $this->jsonReturns(true, '接入人保补录关系人接口成功');
            } else {
                return $this->jsonReturns(false, str_replace("<br/>", "", $finalData['errorMsg']));
            }
        } else {
            return $this->jsonReturns(false, '请求人保补录关系人接口失败');
        }
    }

}